Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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 spaceThanks

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

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
endThanks very much for your help

![]() |
![]() |
![]() |

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