Hi All,
I have a small requirement in which i need to search for specific folders and bring out the file names in those folder and also the line 1 characters 49 to 17.
It is possible to do this in UNIX. I am a beginner.
Any help would be highly appreciated.
Thanks
Karan
nua7
October 6, 2008, 2:54am
2
Giving some examples here would help everyone...
For example
I have a folder "archive" in it i have a folder 0808 and 0809.
Then I have a folder arc_transferred in both of them.
Then multiple folders are there in arc_transferred.
I am looking to search in these folders ...find out the file names and print the first line which is starting with XRI01 the characters 49 to 17.
Hope this information helps.
Thanks
Karan
era
October 6, 2008, 3:29am
4
What do you mean by "49 to 17"? The characters 17 to 49 in reverse order? Or the 17 characters starting at position 49?
17 characters starting at position 49.
era
October 6, 2008, 3:44am
6
for file in archive/080[89]/arc_transferred/*; do
egrep '^.{48,61}XRI01' | head -1
done
You could do the same with a sed script, and avoid the for loop, but this is probably easier to extend and adapt if it doesn't work exactly the way you like. (Check if the egrep offsets are correct; your idea of "first" and "17 positions" might differ from mine.)
it didnt give me any output...can i redirect the output to a file??? on the Unix box
era
October 6, 2008, 3:58am
8
If it didn't give any output, there were no matches.
To redirect the output from command to file, use command > file
The command can be a complex one, such as for f in stuff; do ... done >file
XRI01IFTMIN AGFA AGFADKCPH
In the above line i want to take the value from 49 position to 17 characters.
All the files in the folder start with XRI01 as shown above.
I dont knw why it didnt match anything. As files are there in the folders with such criteria.
Thanks
Karan
era
October 6, 2008, 5:32am
10
I misunderstood your requirement; I thought we should look for XRI01 starting at position 49.
for file in archive/080[89]/arc_transferred/*; do
grep '^XRI01' "$file"| head -1 | cut -c49-66
done >file
Again, you might want to replace the grep | head | cut with a sed or Perl one-liner.
sed -e '/^XRI01/!d' -e 's/.{48}\(.{1,17}\).*/\1/' -ep -eq "$file"
If your sed doesn't understand {m,n} try with \{m,n\} or maybe switch to Perl or something.
It gave an output file of size 0 KB...i didnt understand y