LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   generate new string from a text file (https://www.linuxquestions.org/questions/programming-9/generate-new-string-from-a-text-file-589985/)

walterwaston 10-07-2007 12:29 AM

generate new string from a text file
 
Hi,

I have a file and the content looks like this:

line1
line2
File #5 : found
'/u01/testing.txt'
line5
line6
line7
File #12 : found
'/u01/testabc.txt'
line10
line11

I want to write a bash script to give me the output:

The file 5 is '/u01/testing.txt'
The file 12 is '/u01/testabc.txt'


As I am new in shell script, can anyone tell me how to do this?

Thanks!!
Walter

macemoneta 10-07-2007 01:03 AM

This will do it:

Code:

grep -A1 " : found" theFile | grep -v -- "--" | paste - -

angrybanana 10-08-2007 02:14 AM

Code:

$ cat myfile
line1
line2
File #5 : found
'/u01/testing.txt'
line5
line6
line7
File #12 : found
'/u01/testabc.txt'
line10
line11

$ awk '(match($0 ,"File #(.*) : found",a)) {
          printf "the file "a[1]" is "; getline; print}' 'myfile'

the file 5 is '/u01/testing.txt'
the file 12 is '/u01/testabc.txt'

Hope that helps.


All times are GMT -5. The time now is 05:35 PM.