- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: grep command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:31 AM
04-18-2006 02:31 AM
USERNAME:john.doe
EMAIL:jonh.doe@yahoo.com
ADDRESS:somewhere
PHONENUMBER:12345
USERNAME:john.doe
EMAIL:jonh.doe@yahoo.com
ADDRESS:somewhere
PHONENUMBER:12345
How do I grep the file so that the output will order the data in the following way:The output from grep should be:
1)USERNAME:john.doe
2)EMAIL:jonh.doe@yahoo.com
3)PHONENUMBER:12345
4)USERNAME:john.doe
5)EMAIL:jonh.doe@yahoo.com
6)PHONENUMBER:12345
Solved! Go to Solution.
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:34 AM
04-18-2006 02:34 AM
Re: grep command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:35 AM
04-18-2006 02:35 AM
Re: grep command
grep -v "^ADDRESS:" filename
-v prints all lines that don't match the pattern.
^ designates the pattern should be at the beginning of the line.
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:39 AM
04-18-2006 02:39 AM
Re: grep command
Filters like 'grep' make one-pass through a file, and hence your output will occur in the order the matches appear in the input source.
You can do:
# grep -e USERNAME -e EMAIL -e PHONENUMBER filename
...and you will see the order you posted as ouput if that's the sequential order of the input file.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:45 AM
04-18-2006 02:45 AM
Re: grep command
Is there any advantage from using grep -e to using egrep?
How do I number the lines followed by a bracket?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:45 AM
04-18-2006 02:45 AM
Re: grep command
egrep "USERNAME|EMAIL|PHONENUMBER"
Chan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:48 AM
04-18-2006 02:48 AM
Re: grep command
0 points for this reply.
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:53 AM
04-18-2006 02:53 AM
Re: grep command
grep -v "^ADDRESS:" filename | while read LINE
do
echo "${INDEX})${LINE}"
INDEX=$((${INDEX}+1))
done
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:53 AM
04-18-2006 02:53 AM
Re: grep command
On HP-UX 'grep -E' (uppercase!) provides the same features as 'egrep'.
http://www.docs.hp.com/en/B2355-60103/grep.1.html
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:54 AM
04-18-2006 02:54 AM
Re: grep command
I opened two 3 sessions and assigning points on other threads and forget to submit this...
I have not seen your reply..
I am fine with big fat "0"
Chan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 02:59 AM
04-18-2006 02:59 AM
Re: grep command
That was only a small portion of the file that I displayed. The file contains many more fields (that I dont know the names of)appart from ADDRESS that I dont need. I only know the names of the fields that I need hence deleting is not an option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 03:01 AM
04-18-2006 03:01 AM
Re: grep command
Oh, and to show the linenumber on which the file matched, add the '-n' switch to your command"
# grep -n -e USERNAME -e EMAIL -e PHONENUMBER
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 03:02 AM
04-18-2006 03:02 AM
Re: grep command
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 03:03 AM
04-18-2006 03:03 AM
Re: grep command
Try this piplined construct...
# grep -v '^ADDRESS' input_file | awk '{print NR")"$0}'
hope it helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 03:06 AM
04-18-2006 03:06 AM
Re: grep command
Thank you for your help, but I dont need the line number that it matches. I just simply want to display a number for each line followed by a bracket.
For example: with -n the match might be at line 55 but I would need to display the number of the line corresponding to the output screen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 03:10 AM
04-18-2006 03:10 AM
Re: grep command
If I understand correctly, you want to number the lines of your screen output. You can do:
# grep -e USERNAME -e EMAIL -e PHONENUMBER filename | cat -n | more
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 03:14 AM
04-18-2006 03:14 AM
Re: grep command
BEGIN {LINE=1}
!/ADDRESS/ {print LINE")" $0 ; LINE++}
then:
awk -f awk_script your_file
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2006 03:46 AM
04-18-2006 03:46 AM