LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-07-2007, 12:29 AM   #1
walterwaston
LQ Newbie
 
Registered: Oct 2007
Posts: 1

Rep: Reputation: 0
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
 
Old 10-07-2007, 01:03 AM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 326Reputation: 326Reputation: 326Reputation: 326
This will do it:

Code:
grep -A1 " : found" theFile | grep -v -- "--" | paste - -
 
Old 10-08-2007, 02:14 AM   #3
angrybanana
Member
 
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
Thumbs up

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.

Last edited by angrybanana; 10-08-2007 at 02:44 AM. Reason: Changed code, so it's clearer
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to replace a string in a text file jpan Linux - General 3 10-14-2012 06:17 PM
C++ Text File into String Array p2pfire Programming 2 09-18-2007 03:59 AM
How can I append text to a string in a file HGeneAnthony Linux - Newbie 4 03-01-2007 12:16 PM
How to pick a string from a text file? sdandeker Linux - General 1 02-12-2004 04:17 AM
Parsing a file for a string of text jamesmwlv Linux - General 2 12-02-2002 07:13 PM


All times are GMT -5. The time now is 06:17 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration