Input File : Test.txt
-rw-r--r-- 1 dev dev 93K Sep 18 05:37 Server-23091805496-2-AC.log
-rw-r--r-- 1 dev dev 40K Sep 18 05:44 ServerM-23090331-5709-log.log
-rw-r--r-- 1 dev dev 484K Sep 18 05:46 Server-280334-12570-log.log
-rw-r--r-- 1 dev dev 235K Sep 18 05:47 Server-233405500-1-AC.log
Output in 1st File :
Sep 18 05:37 Server-23091805496-2-AC.log
Sep 18 05:44 ServerM-23090331-5709-log.log
Sep 18 05:46 Server-280334-12570-log.log
Sep 18 05:47 Server-233405500-1-AC.log
Output in 2nd File :
Server-23091805496-2-AC.log
ServerM-23090331-5709-log.log
Server-280334-12570-log.log
Server-233405500-1-AC.log
Tried Below :
1. sed ‘s/ /\n/g’ Test.txt
2. ls -ltr | grep "Sep 18 08:" |sed -n ‘1p’|cut -d ‘ ‘ -f2
>Solution :
One answer could be:
sed <input.txt -e 's/.*K //g;w file1.txt' -e 's/.* //g;' >file2.txt
Or better:
sed <input.txt -e '
s/^\([^[:space:]]\+[[:space:]]\+\)\{5\}//;
w file1.txt' -e '
s/\([^[:space:]]\+[[:space:]]\+\)\{3\}//;' >file2.txt
Where
-
sedis run only once, without any fork to other tool, -
1st removing everything until
Kin first proposal,removing non-spaces followed by spaces, repeated 5 times, in second proposal
-
then
wwrite to filefile1.txt -
At this point, script end with second quote, then a second script start with
-esed argument. -
Removing everything until last space in first proposal,
removing non-spaces followed by spaces, repeated 3 times, in second proposal
-
Then send
sed‘s standard output tofile2.txt