Working with grep-output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Working with grep-output
# 1  
Old 12-12-2012
Working with grep-output

Hi, 1st post

Sorry for borrowing the thread.

Hopefully this is doable.

I need to write a script where I need to pick information from my grep-results.

Code:
grep -n "s_" file | head -n 1

Output is like this:
Code:
6:s_9: 11-664 Fam_g442_99

So this gives me the first line of the file which includes "s_" .

I need to pick those s_9, 11-664 and Fam_c606_1 separately that the script can rename the txt-file's subfolders with this information.

After this is done, my script will do the grep with | head -n 2 and repeat the sequence.

Many thanks in advance

Last edited by Scrutinizer; 12-12-2012 at 08:50 AM.. Reason: code tags
# 2  
Old 12-12-2012
Code:
#!/bin/bash
declare -a array=( $(awk  -F '[ :]'   '$2 ~ /^s_/  {printf("%s %s %s ", $2, $3, $4) }' filename ) )
# you now have an array of name pieces
# you can access them as groups of three:

element=0
while [ $element -lt ${#arr} ]
do
     part1=${arr[element]}   
     element=$(( $element + 1 ))
     part2=${arr[element]}
     element=$(( $element + 1 ))   
     part3=${arr[element]}   
     element=$(( $element + 1 ))
     echo "part1=$part1  part2=$part2 part3=$part3"
     # rename your files here
done

# 3  
Old 12-13-2012
Thanks in advance!

I'll give it a try
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep with variable not working

Hello, I am using below code : export ORAR=orp712z.int.thomsonreuters.com #echo $ORAR; if echo $ORAR|grep -i "_" then ORACLE_SID1= echo $ORAR|cut -f2 -d "_" echo $ORACLE_SID1 ORACLE_SID=fgrep "$ORACLE_SID1" /etc/oratab|cut -f1 -d ":" #echo $ORACLE_SID else ORACLE_SID1= echo $ORAR|cut... (1 Reply)
Discussion started by: admin_db
1 Replies

2. Shell Programming and Scripting

Grep not working on mac

Hi all, I got a new mac and can't get grep, awk etc to work. I tried the following command: grep DICER test.txt output: AGOER text.txt looks like this: DICER DICER AGOWhat is wrong? Please use code tags (23 Replies)
Discussion started by: Palgrave
23 Replies

3. Shell Programming and Scripting

-v and -f option for grep not working

In solaris, i m trying to find the files having a particulat extension and then from the list i want to exclude those files which is present in a file. But it seems the -f and -v option are not working find $source -type f -name $extn | /usr/xpg4/bin/grep -F -v -f $exclude | while read... (7 Replies)
Discussion started by: millan
7 Replies

4. Shell Programming and Scripting

How to grep the desired output and output to a file?

currently I have process from a raw file to this stage ALTER TABLE "EXCEL_ADMIN"."TC_TXN_VOID" ADD CONSTRAINT "PK_TC_TXN_VOID" PRIMARY KEY ("TC_TXN_IID") ALTER TABLE "EXCEL_ADMIN"."TC_TXN_AMT" ADD CONSTRAINT "PK_TC_TXN_AMT" PRIMARY KEY ("TC_TXN_AMT_IID") ALTER TABLE... (10 Replies)
Discussion started by: jediwannabe
10 Replies

5. Programming

Grep not working of jobs

I am using csh. Output of command jobs {145}>jobs + Running /home/alokg/nedit-5.5-Linux-x86/nedit .cshrc Running /home/alokg/nedit-5.5-Linux-x86/nedit build/irun_usb2.log Running /home/alokg/nedit-5.5-Linux-x86/nedit... (3 Replies)
Discussion started by: alokgarg79
3 Replies

6. UNIX for Dummies Questions & Answers

grep for word not working

Hi All..I need a help i am trying to find a word using below script whereas the word exists in my file nitin.txt as a directory but still i am getting "word not found" output..Your suggestions welcomed.: #to check for existence of nitin #!/bin/bash cd /apps/uat1/deploy/app ls -lrt >... (4 Replies)
Discussion started by: nattynitin
4 Replies

7. UNIX for Dummies Questions & Answers

grep -f not working

Hello, I'm going crazy about this. I'm using grep to filter some values as in pas -ef | grep asterisk. When I use the same with -f somefile something weird happens, if somefile is created with vi it'll work, if somefile is created with vi but values are pasted from an Excell file it will not work.... (2 Replies)
Discussion started by: seveman
2 Replies

8. Shell Programming and Scripting

grep not working ????

Hi, I've prob in doing grep. I want to grep line staring with number 531250 in the 1st column from a file (example in picture attached below) using command grep -w "531250" file my ideal result should be 531250 1 21 42.1 100 1e-05 ... (8 Replies)
Discussion started by: masterpiece
8 Replies

9. UNIX for Dummies Questions & Answers

grep not working

This condition is not able to grep , can any one tell what's wrong with this part. I am able to see from unix command but not with host script. echo "Checking for Loader Status " >> $REPFILE if test $? = 0 then echo "Successful termination of SQL*Loader "$LOADER1 >>... (5 Replies)
Discussion started by: u263066
5 Replies

10. UNIX for Advanced & Expert Users

cat and grep not working

I am trying to cat a file and then grep that file for a number. I can do it fine on other files but this particular file will not do anything. I tried running it on an older file from the same device but it is just not working. The file is nothing more than a flat file on a unix box. Here is just a... (3 Replies)
Discussion started by: jphess
3 Replies
Login or Register to Ask a Question