- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- need remove second field
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-12-2011 06:10 PM
тАО04-12-2011 06:10 PM
I have a file which looks like this -
host packagename -install -app Appname
packagename is of this pattern -
Appname-20110304-131123-hexanumbers
1)The list is pretty long and I want to remove the packagenames from all entries. How can I remove the second entry from each row(delete the packagename)?
2)Also it would be helpful if I can know how to remove the entries after Appname in the packagename.(so instead of Appname-20110304-131123-hexanumbers I can get Appname in the second field)?
Thanks,
allan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-12-2011 06:11 PM
тАО04-12-2011 06:11 PM
Re: need remove second field
(replace Appname-20110304-131123-hexanumbers with the word text)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-12-2011 07:19 PM
тАО04-12-2011 07:19 PM
SolutionWrite a shell script?
man sed
alp$ echo 'host Appname-20110304-131123-hexanumbers -install -app Appname' | \
sed -e 's/ [^ ]* / /'
host -install -app Appname
alp$ echo 'host Appname-20110304-131123-hexanumbers -install -app Appname' | \
sed -e 's/-.*$//'
host Appname
alp$ echo 'host Appname-20110304-131123-hexanumbers -install -app Appname' | \
sed -e 's/ [^ ]* / text /'
host text -install -app Appname
It's not easy to do the whole job without
knowing from where "text" will be coming.
/ [^ ]* /
means a space, any number ("*") of non-space
characters ("[^ ]"), and a space.
/-.*$/
means a "-", any number ("*") of any
characters ("."), and the end of the line
("$").
man sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2011 02:29 AM
тАО04-13-2011 02:29 AM
Re: need remove second field
awk '{print $1, $3, $4, $5}' file
>2) Also it would be helpful if I can know how to remove the entries after Appname in the packagename. (so I can get Appname in the second field)?
Is this Appname the same as field 5?
awk '{print $1, $5, $3, $4, $5}' file
Otherwise:
awk '
{
dash = index($2 , "-") # find "-"
if (dash == 0)
app = $2
else
app = substr($2, 1, dash-1)
print $1, app, $3, $4, $5
}' file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2011 03:01 AM
тАО04-13-2011 03:01 AM
Re: need remove second field
awk -v text="$text_variable" '{print $1, text, $3, $4, $5}' file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2011 05:09 AM
тАО04-13-2011 05:09 AM
Re: need remove second field
>2) Also it would be helpful if I can know how to remove the entries after Appname in the packagename. (so I can get Appname in the second field)?
You can let 'awk' split subfields on a different deliminter, too:
# X="host Appname-20110304-131123-hexanumbers -install -app Appname"
# echo${X}|awk '{if (split($2,app,"-") > 0) {print $1,app[1],$3,$4,$5} else {print}}'
host Appname -install -app Appname
As always, TMTOWTDI
Regards!
...JRF...