Computing.Net > Forums > Unix > how to remove the first field

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how to remove the first field

Reply to Message Icon

Name: jds
Date: June 16, 2007 at 00:32:41 Pacific
OS: windowsXP
CPU/Ram: petium III/ram 256
Comment:

Hi, I have file like this:
======================
1232 asdasds:
121 wefefsedfsd
asdsd
!34234 sdfdf
43423 fdsfsd
423434 end
===================
I would like to remove the first field which start with numbers, such as: 43423 fdsfsd
after removal, it should look like this:
without space in front
+++++++++++++++++
asdasds:
wefefsedfsd
asdsd
!34234 sdfdf
fdsfsd
end
+++++++++++++++
I tried this way
sed 's/^[0-9]*//g;
s/^[ \t]*//' file1>file2
It works but Is there any better way to do this? like remove the the first filed start with number all the way upto first space?
After above step, I also want to reformat the text like this
=====================
# any line end with : add one space in front
asdasds:
wefefsedfsd #indented the contains
asdsd
!34234 sdfdf
fdsfsd
end # any line with onle word end add one space
======================
How can I do this?
Any hint is much appreciated.
Thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: jds
Date: June 16, 2007 at 00:39:04 Pacific
Reply:

Hi after I post the above message it seems not displayed properly:
for the final text:
# any line end with : add one space in front
asdasds: #one space in front
wefefsedfsd #indented the contains
asdsd #indented the contains
!34234 sdfdf #indented the contains
fdsfsd #indented the contains
end # any line with onle word end add one space

Thanks


0

Response Number 2
Name: ghostdog
Date: June 16, 2007 at 02:06:22 Pacific
Reply:

[code]
awk '$1 ~ /[0-9]+/ {
if ($NF ~ /:$/) {
$1 = " "
}
else {
$1=""
}

gsub("^ ","",$0)

}
{print $0}

' "file"
[/code]


0

Response Number 3
Name: jds
Date: June 19, 2007 at 13:19:24 Pacific
Reply:

Thanks Ghostdog.
I tried the script and got the following result:
asdasds:
wefefsedfsd
asdsd
sdfdf
fdsfsd
end
What I need is remove first field START with number ( not contains number). so the script is missing this line:
!34234 sdfdf
Here is a new file to test
1232 asdasds:
121 wefefsedfsd
asdsd
!34234 sdfdf
43423 fdsfsd
MAP1 TEST,S,4
MAP2 TEST2,4
MAP3 TEST3 S,1
423434 end
After script run I want to get this result:
asdasds:
wefefsedfsd
asdsd
!34234 sdfdf
fdsfsd
MAP1 TEST,S,4
MAP2 TEST2,4
MAP3 TEST3 S,1
end

Thanks very much for your help


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: how to remove the first field

how to get the last field www.computing.net/answers/unix/how-to-get-the-last-field/6529.html

How to Remove LILO from Windows NT boot www.computing.net/answers/unix/how-to-remove-lilo-from-windows-nt-boot-/2230.html

How to remove files www.computing.net/answers/unix/how-to-remove-files/7421.html