greping word after new line character


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting greping word after new line character
# 1  
Old 06-17-2011
greping word after new line character

how grep all user from the below looking file:

Code:
User_Alias      ADMIN1 = horacel, matthes, caseyl, alexl2, \
                         jackl, johnnyzh, maheshm, jihuih, davidw, \
                         christh, williaml,jasminez
User_Alias      ADMIN2 = tomc, apitssc, fengh, guh, kail, saizhuzh, \
                        terryl, timg, xiaowens, xiaoyeh, haitaow,haiyanx, \
                        liliangc, xiaohuiq, yuanyuan, huizh, juanw, \
                        liangyou, akandasw, babukart, veerasam, pothann, \
                        thamodar, mramesh, mrenjith

User_Alias      TCSADMS = ramachv, manojid, saravac, jasons, abubaks, \
                          girishb, ramachp, arindab, ericli, nandak


Last edited by pludi; 06-17-2011 at 07:34 AM..
# 2  
Old 06-17-2011
Code:
cat <FILE> | sed '/\\$/N; s/[\\\n]//g; s/  */ /g ' | grep <USER>

# 3  
Old 06-17-2011
Quote:
Originally Posted by manojit123

Let the file be Users.txt

Code:
User_Alias      ADMIN1 = horacel, matthes, caseyl, alexl2, \
                         jackl, johnnyzh, maheshm, jihuih, davidw, \
                         christh, williaml,jasminez
User_Alias      ADMIN2 = tomc, apitssc, fengh, guh, kail, saizhuzh, \
                        terryl, timg, xiaowens, xiaoyeh, haitaow,haiyanx, \
                        liliangc, xiaohuiq, yuanyuan, huizh, juanw, \
                        liangyou, akandasw, babukart, veerasam, pothann, \
                        thamodar, mramesh, mrenjith

User_Alias      TCSADMS = ramachv, manojid, saravac, jasons, abubaks, \
                          girishb, ramachp, arindab, ericli, nandak



Code:
echo `cat Users.txt | cut -d= -f2` | awk '!x[$0]++' |awk -F"[,]" '{ for (i=1; i<=NF; i++) print $i }'


it will handle upto comma.. But i am sorry i couldn't handle escape charactor.

.
# 4  
Old 06-17-2011
Not get the desided output .. Pls help
# 5  
Old 06-17-2011
  1. Please use complete english words and sentences.
  2. "Not get the desided output"? You never told us what output you expect. Or how the output from those commands is different from what you expect. We ain't psychic.
# 6  
Old 06-17-2011
Exactly Pludi..

Your heading of the post "greping word after new line character"
and "how grep all user from the below looking file:" it self different.

if posting , please provide us how you want your OUTPUT exactly or how your OUTPUT will look like atleast.

.
# 7  
Old 06-17-2011
Sorry guys.seems my requirement is not clear to the forum. My requirement is I want to get only the listing of user id from the pasted text as below. once I grep User_Alias only the first line of user I'm able to get but not the other user which are separated by "\" new line character. Pls help..
horacel
matthe
caseyl
alexl2jackl
johnnyzh
maheshm
jihuih
davidw
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add a character after the first word/space on each line?

Hi:) I have a large file ( couple thousand lines ) and I'm trying to add a character after the first word/space on each line. eg: First line of text Second line of text Third line of text Fourth line of text Fifth line of text I'd like to accomplish: First - line of text Second... (8 Replies)
Discussion started by: martinsmith
8 Replies

2. Shell Programming and Scripting

Find word in a line and output in which line the word occurs / no. of times it occurred

I have a file: file.txt, which contains the following data in it. This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt My name is not Karl, my name is Karl Joey What is your name? Do you know your name and... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

3. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

4. Shell Programming and Scripting

Greping entire XML which has special character

I have an XML with has special character Â. I wrote a Grep command to find out the special character grep -i  Filename | grep ShipAddress2 I need the help to know how to find out special character such as  and get the whole XML listed assuming there are more xml data of similar sort for... (3 Replies)
Discussion started by: murali1687
3 Replies

5. UNIX for Advanced & Expert Users

Count specific word or character per line

Hi, I need help regarding counting specific word or character per line and validate it against a specific number i.e 10. And if number of character equals the specific number then that line will be part of the output. Specific number = 6 Specific word or char = || Sample data:... (1 Reply)
Discussion started by: janzper
1 Replies

6. Shell Programming and Scripting

Need Help with greping two line from a file Pls help ASAP

Hi all - I''m in a little bit of jam - If you can please help I have a file that has the following content ( please see below) I need to read the file and then get this result in this format ------------- To put out in this format name: sophis Total: 22328 name: tca ... (2 Replies)
Discussion started by: mnassiri
2 Replies

7. UNIX for Dummies Questions & Answers

Greping next line after grep match

Hi All I have a file with tha same line multiple times and its easy to grep out those lines using grep "pattern" filealthough I need to know exactly what the next line after those lines are Can anyone please shed some light on this on how i can simultaneously grep the pattern and the next line... (9 Replies)
Discussion started by: pawannoel
9 Replies

8. Shell Programming and Scripting

Command to parse a word character by character

Hi All, Can anyone help me please, I have a word like below. 6,76 I want to read this word and check if it has "," (comma) and if yes then i want to replace it with "." (dot). That means i want to be changed to 6.76 If the word doesnot contain "," then its should not be changed. Eg. ... (6 Replies)
Discussion started by: girish.raos
6 Replies

9. Shell Programming and Scripting

Print word 1 in line 1 and word 2 in line 2 if it matches a pattern

i have a file in this pattern MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH1 word1 IMAGE word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1 word2 word3 word4 MATCH2 word1... (7 Replies)
Discussion started by: bangaram
7 Replies

10. Shell Programming and Scripting

Looking for a single line to count how many times one character occurs in a word...

I've been looking on the internet, and haven't found anything simple enough to use in my code. All I want to do is count how many times "-" occurs in a string of characters (as a package name). It seems it should be very simple, and shouldn't require more than one line to accomplish. And this is... (2 Replies)
Discussion started by: Shingoshi
2 Replies
Login or Register to Ask a Question