LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 08-08-2011, 12:21 PM   #1
emili1001
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Rep: Reputation: Disabled
How to find the position of the first space in a line?


Hi guys,

I am trying to edit a large bunch of files. Each file has four columns and I want to get rid of the first one, but in each line the number of the first column changes. the number in the first column ranges from 1 digit to 5. For example

1 aaaaa bbbbbb ccccc
23 aaaaa bbbbbb ccccc
15343 aaaaa bbbbbb ccccc

and the desired format would be

aaaaa bbbbbb ccccc
aaaaa bbbbbb ccccc
aaaaa bbbbbb ccccc

Thanks

e
 
Old 08-08-2011, 01:38 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Please use [code][/code] tags around your code, to preserve formatting and to improve readability.

You have lots of options for this. The most basic is to use the cut utility.
Code:
cut -d " " -f 2- file.txt
It can also be done by either sed or awk, among others, with a simple regular expression.
Code:
sed -r 's/^[^ ]+ //' file.txt
Code:
awk '{ sub( /^[^ ]+ /,"" ) ; print }' file.txt
Since awk is a field-based interpreter, and you have a small number of fixed fields, you could also simply tell it to print every field except the first, similar to cut.
Code:
awk '{ print $2,$3,$4 }' file.txt
sed can edit the file in-place by using its -i option. cut and awk's output would have to be redirected to a temporary file.
 
1 members found this post helpful.
Old 08-08-2011, 02:02 PM   #3
emili1001
LQ Newbie
 
Registered: Aug 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thumbs up

Thanks David the H.

that work out perfectly in my script.

Thanks!
 
  


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
BASH Sort list by end of line to x position in each line? SilversleevesX Programming 14 08-19-2010 09:30 PM
[SOLVED] How to get the cursor position line at the mid of the windows in vim? cola Linux - Newbie 5 03-28-2010 11:18 AM
Print a line on n'th position within a large file...will PIPE optimize this? f1dg3t Linux - Newbie 6 03-19-2010 03:41 AM
deletion of line above the cursor position. dina3e Linux - Newbie 1 04-07-2008 10:41 PM


All times are GMT -5. The time now is 04:51 AM.

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