Reputation: 3
When using Sed to change the format of the information with this code
sed -e "1,/\[option\]/i user id is:" -e '/^#/d' -e 's/~//g' /test/data/USER.FIDS
The information comes out looking like below.....
user id is:
qqq TTK
user id is:
jeff TTL RODGERS
user id is:
mark TP4 THOMSON
What I need is for the information to come out looking like this below...
user id is: qqq TTK
user id is: jeff TTL RODGERS
user id is: mark TP4 THOMSON
Upvotes: 0
Views: 298
Reputation: 19982
It looks like /test/data/USER.FIDS
only contains names, and you can use
sed '/^#/d; s/^/user id is: /;s/~//g' /test/data/USER.FIDS
Upvotes: 0
Reputation: 23667
Since sample input wasn't provided, I'm creating my own and focusing only on the part that needs to be changed. Instead of using i
command, use s
like shown below:
# 'i' command will insert content before matching lines
$ seq 5 | sed '/[135]/i user id is: '
user id is:
1
2
user id is:
3
4
user id is:
5
# with 's' command, you can add content to the same line
$ seq 5 | sed '/[135]/ s/^/user id is: /'
user id is: 1
2
user id is: 3
4
user id is: 5
Upvotes: 3
Reputation: 133428
In case you are ok with awk
, you could try following. Since there is no sample data provided so this has been run and tested with your shown samples output of your shown command.
your_command |
awk '
{
printf("%s",$0~/^user id/?(FNR>1?ORS:"")$0 OFS:$0)
}
END{
print ""
}
' | column -t
Upvotes: 2