Hi Guys,
I am new to Unix, I need shell script in Unix as follows
I have 3 files with .OUT as extensions, I need a script to read these 3 files and match the character positions from 28-35 with the string 20090203, if it matches with this pattern in any record, take that record and write it to a new file.
You can use awk for that:
awk 'substr($0,28,8)==date {print > output}' date=20090203 output=output.file *.OUT
Hi,
Thanks for your quick response,
I have tried the command given below, but i am not getting any output after execution, i.e., it is not creating any outputfile after executing this command, and for your reference i am using ubuntu 6.0 version in my laptop and executing this command at the shell prompt, please suggest me, if i am doing anything wrong......
You should post a data sample data (use [code] tags) or reconsider your problem.
Try this out..
This code will take all files with '.out' as extension and search for the string in those file and finally print the desired lines into a new file.
ls *.out | while read name
do
awk '{ print substr ($0, 6 , 15 ); }' $name | grep 20090203 >> new
done
It is just displaying the given search pattern, i.e., once the given script is executed it is just storing 20090203 in the output file, but it is not our requirement
awk -v date=20090203 'substr($0,28,8)==date' *.OUT > output.file