Grep text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep text
# 1  
Old 09-28-2011
Grep text

I have a file with the input as below:
Code:
Host = example.com,
 service = void
Host = example1.com,
 service = void1
Host = example2.com,
 service = void2

Need the output as below:
Code:
example.com,void
example1.com,void1
example2.com,void2

Please reply

Thanks

Last edited by vbe; 09-28-2011 at 09:23 AM.. Reason: Use code tags for data/code next time!
# 2  
Old 09-28-2011
Code:
 
$ awk -F\= 'NR%2==1{a=$2;getline;printf("%s%s\n",a,$2)}' inputfile
 example.com, void
 example1.com, void1
 example2.com, void2

# 3  
Old 09-28-2011
Code:
$ awk -F= '{print $2|"paste - -"}' infile
 example.com,    void
 example1.com,   void1
 example2.com,   void2
$

# 4  
Old 09-28-2011
Code:
awk '{p=$NF;getline;print p $NF}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep text and see all section

Hello I am looking for a way to look in files and to grep text and see the all section of the text ! Sharon123 deed 10000 class 360 ! sharon456 2000 deed ! Sharon789 live 3000 ! To grep "deed "an see the all section (5 Replies)
Discussion started by: sharong
5 Replies

2. Linux

Grep the ip to a text file

Hi all, We Have Squid server, We need to get the particular IP's log from /var/log/squid/access.log, if i need to get only the log's of 192.168.0.99, How can i get the log's to a separate file. Here is the sample log what i have got from access.log file 1392706763.690 847... (2 Replies)
Discussion started by: babinlonston
2 Replies

3. Shell Programming and Scripting

Grep text matching problem with script which checks if web page contains text.

I wrote a Bash script which checks to see if a text string exists on a web page and then sends me an email if it does (or does not e.g. "Out of stock"). I run it from my crontab, it's quite handy from time to time and I've been using it for a few years now. The script uses wget to download an... (6 Replies)
Discussion started by: gencon
6 Replies

4. Shell Programming and Scripting

Matching text using grep

Hi folks... Relatively new to scripting, but really struggling with something that will no doubt be second nature to most people on here: Trying to get an exact match on $sub, where sub is an ip address. subnet () { clear while true do ... (18 Replies)
Discussion started by: CiCa
18 Replies

5. UNIX for Dummies Questions & Answers

How to grep multiple lines from a text file using another text file?

I would like to use grep to select multiple lines from a text file using a single-column text file. Basically I want to only select lines from the first text file where the second column of the first text file matches the second text file. How do I go about doing that? Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

6. UNIX Desktop Questions & Answers

grep a range of text

hey, i need to grep / awk a list of "DEV ID" range for example for greping 0936 - 09C1 from this file: 0x5000097310036d05 558 1 20531 LOCAL GLOBAL 42048000 YES 0x8e36c8bd07ce9e13 DEV ID: 0933 0x5000097310036d05 559 1 20531 ... (1 Reply)
Discussion started by: boaz733
1 Replies

7. Shell Programming and Scripting

Text file with grep

Sirs, i am trying to create simple script file.. what i do is grep for a pattern and output 1 line after it. exmp: grep -A 1 time files.txt Output: time file1 time file2 --- Is there some option I can use so I can get on result each 2 lines combined as one file? like: time file1... (2 Replies)
Discussion started by: alekkz
2 Replies

8. Shell Programming and Scripting

grep for text and lines above and below

hi all, in ksh i wanted to grep for some text and also include a few lines above and below that text. how do i do that ??? i am trying to get my script to print out request and response from the server log file. getting the request is easy, i just do a grep -i "request" from log but i... (5 Replies)
Discussion started by: cesarNZ
5 Replies

9. UNIX for Dummies Questions & Answers

retrieve text after grep

I am trying to search for a pattern in a file containing xml - When I match the search I want to retrieve all the text within the xml brackets.. Whats the best way to read in data between xml tags in a shell script? ie.. xml returned which I have in a file now is something like below:... (2 Replies)
Discussion started by: frustrated1
2 Replies

10. UNIX for Dummies Questions & Answers

grep multiple text files in folder into 1 text file?

How do I use the grep command to take mutiple text files in a folder and make one huge text file out of them. I'm using Mac OS X and can not find a text tool that does it so I figured I'd resort to the BSD Unix CLI for a solution... there are 5,300 files that I want to write to one huge file so... (7 Replies)
Discussion started by: coppertone
7 Replies
Login or Register to Ask a Question