I want the sed command to work on all files in a directory and output the result into a new file. If f is val1.txt, the name of the output file should be val1_ended.txt -this is what I am trying to do with echo and sed, but it doesn't work. Any help would be appreciated. Thank you!
files= ls *.txt
echo "${files}"
for f in ${files}$
do
echo $f
sed -n -e 's/Trial End/&/p' $f>` echo $f | sed 's/.txt$/_ended.txt/g' `
done
In my input files, lines are as such:
3413476 999.3 549.3 1876.0 32768.0
3413477 1000.7 549.6 1880.0 32768.0
3413478 999.3 551.1 1875.0 32768.0
INPUT 3413485 127
END 3413485 SAMPLES EVENTS RES 59.84 45.82
MSG 3413491 Trial End 2
MSG 3414099 RECCFG CR 1000 0 0 R
While in output, I want all lines where it finds the pattern "Trial End":
MSG 3411256 Trial End 1
MSG 3413491 Trial End 2
MSG 3415678 Trial End 3
MSG 3417842 Trial End 4
MSG 3420114 Trial End 5
files=$(ls *.txt)
and it is not a good reference. You can do this in thefor
line asfor f in *.txt
. And for me to make a comment on your sed command, I need to see a few sample lines from your input file and your expected output.