[Solved] Help with grep script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Help with grep script
# 8  
Old 01-26-2013
It should not extract line number: 10 twice. Remove temporary file: test in the beginning so that you will not append data to existing content.
Code:
#!/bin/bash
rm -f test
for i in *.CSV
do
    sed -n '10p' "${i}" >> test
done

This User Gave Thanks to Yoda For This Post:
# 9  
Old 01-26-2013
help with sed script

Yes, I removed file "test" and ran the script. There are 12 files in the sandbox directory. When the file "test" is generated again from the script the results are 24 lines:

Code:
SUBJECT ID:b2425 c57 2-6mg low Fe
SUBJECT ID:b2428 c57 2-6mg low Fe
SUBJECT ID:b2389 c57 2g hi Fe
SUBJECT ID:b2390 c57 2g hi Fe
SUBJECT ID:b2391 c57 2g hi Fe
SUBJECT ID:b2392 c57 2g hi Fe
SUBJECT ID:b2431 c57 2-6 mg low Fe
SUBJECT ID:b2432 c57 2-6mg low Fe
SUBJECT ID:b2393 c57 2g/kg hi Fe
SUBJECT ID:b2394 c57 2g/kg hi Fe
SUBJECT ID:b2433 c57 2-6 mg low Fe
SUBJECT ID:b2434 c57 2-6 mg low Fe
SUBJECT ID:b2425 c57 2-6mg low Fe
SUBJECT ID:b2428 c57 2-6mg low Fe
SUBJECT ID:b2389 c57 2g hi Fe
SUBJECT ID:b2390 c57 2g hi Fe
SUBJECT ID:b2391 c57 2g hi Fe
SUBJECT ID:b2392 c57 2g hi Fe
SUBJECT ID:b2431 c57 2-6 mg low Fe
SUBJECT ID:b2432 c57 2-6mg low Fe
SUBJECT ID:b2393 c57 2g/kg hi Fe
SUBJECT ID:b2394 c57 2g/kg hi Fe
SUBJECT ID:b2433 c57 2-6 mg low Fe
SUBJECT ID:b2434 c57 2-6 mg low Fe

Thanks again,
Bob

---------- Post updated at 01:22 PM ---------- Previous update was at 01:19 PM ----------

I figured it out. It was a typo on my part. The problem is solved.
Thanks for all your help and patients with a "nubee"

Bob

Last edited by radoulov; 01-26-2013 at 01:31 PM..
This User Gave Thanks to bob101 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Having trouble with simple grep search

I have a text file (allWords.txt), that I would like to search through. Here is a snippet of what it looks like... a aah aahed aahing aahs aardvark aardvarks aardwolf ab abaci aback abacus abacuses abaft ...... I would like to use the grep search to search, line by line, for... (8 Replies)
Discussion started by: blackvelvet
8 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Grep multiple files and display first match

I have a need to grep a large number of files, but only display the first result from each file. I have tried to use grep, but am not limited to it. I can use perl and awk as well. Please help! (9 Replies)
Discussion started by: dbiggied
9 Replies

3. Shell Programming and Scripting

[Solved] Issue with grep

Hi everyone I am trying to write a script to check if file systems are mounted, and also validate the permission; then do a whole bunch of other things. I am facing a problem with grep. For example, if the mountpoints are: /dev/XYZ_lv /abc/XYZ jfs2 Nov 25 20:36... (4 Replies)
Discussion started by: nimo
4 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Grep in bash script

Hi Experts, I'm writing script to find out last files and its modified date - unfortunately am having problem with the below script. Error message: "grep: sales.txt: No such file or directory" #!/bin/bash var=1 var1=`awk '{n++} END {print n}' sales.txt` while ] do prod=$var... (6 Replies)
Discussion started by: parpaa
6 Replies

5. UNIX for Advanced & Expert Users

[SOLVED] Grep IP's from xml with name of file

Hi all, actually i have a lot of IP addresses on multiple .xml files on my folder, my tag on xml files are like this, <db-url>jdbc:oracle:thin:@10.100.5.56:1521:DWH01</db-url> i actually can print only the IP addresses awk -F"" '/url/ { print $3 }' *.xml 10.100.5.56 i would like to grep... (2 Replies)
Discussion started by: charli1
2 Replies

6. Shell Programming and Scripting

[Solved] Grep within find command

Platform: AIX 6.1/ksh Question1. I want to grep for the string "CUSTOM_PKMS" in all the files in server except those files with extensions .dbf , .ctl and .dmp I started running the following command but it is taking too long because there are lots of .dbf , .ctl and .dmp files in this... (6 Replies)
Discussion started by: John K
6 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Wildcards used in find, ls and grep commands

Platforms : Solaris 10 and RHEL 5.6 I always get double quotes , single quotes and asteriks mixed up for find, ls and grep commands. The below commands retrieve the correct results. But , unders stress , I get all these mixed up :mad: .So, i wanted to get a clear picture. Please check if... (7 Replies)
Discussion started by: John K
7 Replies

8. Shell Programming and Scripting

[Solved] perl and grep: get a script to look at more then one file

hi guys i have this very messy script, that looks in /var/log/messages.all for an error and reports if it finds the key works how can i get it to look at more then one file, i.e /var/log/message.all * so it looks in old logs as well thanks exit 0 if (isRenderNode(hostname)); my... (4 Replies)
Discussion started by: ab52
4 Replies

9. Shell Programming and Scripting

[solved] Diff between two files by grep

My requiremeny is as follows, I have two files file a A BONES RD,NHILL,3418,VIC 37TH PARALLEL RD,DEEP LEAD,3385,VIC 4 AK RD,OAKEY,4401,QLD A & J FARRS RD,BARMOYA,4703,QLD A B PATTERSON DR,ARUNDEL,4214,QLD A BLAIRS RD,BUCKRABANYULE,3525,VIC file b A BONES... (12 Replies)
Discussion started by: feelmyfrd
12 Replies

10. UNIX for Dummies Questions & Answers

[solved] Script creation (how to include options in the script)

Hi guys i have written a script which takes the options given to him and execute itself accordingly. for example if a script name is doctortux then executing doctortux without option should made doctortux to be executed in automatic mode i.e. doctortux -a or if a doctortux is needed to run in... (4 Replies)
Discussion started by: pinga123
4 Replies
Login or Register to Ask a Question