LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-25-2010, 01:30 PM   #1
stelistul
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Rep: Reputation: 0
need a little bit of help with a comand


i have to delete the second and forth word from a file using sed and to desplay the users that use the comand bash using grep. i need some help with this because i tryed many times but i couldnt get it right . thx in advance
 
Old 03-25-2010, 01:39 PM   #2
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Rep: Reputation: 16
im not clear about your question... do you want to do this all with one command?
 
Old 03-25-2010, 01:42 PM   #3
stelistul
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
no there are two separate problems
 
Old 03-25-2010, 01:53 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
And that "2nd and 4th word of a file" ... do they all come in
one row, or one word per line? We can't really help you w/o
decent input on just WHAT you're trying to achieve, and what
the raw data looks like.


Cheers,
Tink
 
Old 03-25-2010, 01:57 PM   #5
stelistul
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
i am sry if i wasnt that explicit about my problem. with the comand sed i need to delete (i think that means that i have to replace the word with ' ') the 2nd and 4th word from every line of a file. sry again

file: bla1 bla2 bla3 bla4
bla1 bla2 bla3 bla4

result file:

bla1 bla3
bla1 bla3

Last edited by stelistul; 03-25-2010 at 01:59 PM.
 
Old 03-25-2010, 02:13 PM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
I really wonder why this has to be done with sed, smells a bit like homework.....

Here's a sed solution, it is up to you to figure out how this works:

sed 's/\([a-z0-9]* \)[a-z0-9]* \([a-z0-9]* \)[a-z0-9]* \(.*\)/\1\2\3/' infile

It does take into account that more then 4 words could be in a line.

Hope this helps.
 
1 members found this post helpful.
Old 03-25-2010, 02:23 PM   #7
stelistul
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
thx for the quick response i resolved the problem.it was a problem a sintax for me and yeah its a homeworck (a stupid one). thank you very much. BTW can u help me with the grep comand i have no idea there at least give me a hint
 
Old 03-25-2010, 02:39 PM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Syntax for your grep problem:

grep "PATTERN" FILE
The PATTERN is given in the exercise. Which file to use is up to you to find out.
 
Old 03-25-2010, 03:29 PM   #9
stelistul
LQ Newbie
 
Registered: Mar 2010
Posts: 5

Original Poster
Rep: Reputation: 0
thank you
 
  


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
64 bit cpu-64 bit Ubuntu-are there 32 bit app issues? sofasurfer Ubuntu 7 04-09-2014 03:02 PM
timex - what does this comand mean? rust8y Solaris / OpenSolaris 3 01-31-2012 08:11 PM
Why the comand mv so slow ? supersave Linux - General 3 02-09-2010 01:30 PM
LXer: Ubuntu 32-bit, 32-bit PAE, 64-bit Benchmarks LXer Syndicated Linux News 0 12-30-2009 12:00 PM
Question on dd comand. just.srad Linux - General 3 05-02-2008 08:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:38 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration