- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Awk/ GAWK Help Requested: How to get the space out...
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
Forums
Discussions
Discussions
Discussions
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
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
06-10-2005 08:22 AM
06-10-2005 08:22 AM
I have a text file, and from a specific line after, I would like to get the space out.
I mean I'd like to take the space between field1 and field2 ($1,$2) out and make it one field.
How can I merge them?
Example:
Field1 Field2
work/ hoop.htm
I would like to change the above line to:
work/hoop.htm
Thanks for your response.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 08:28 AM
06-10-2005 08:28 AM
Solutionfield1=`echo $line| awk {'print $1'}
field2=`echo $line| awk {'print $2'}
line=`printf ${field1}${field2}`
if you are going to read from a fiel and want to do it for every line
cat file | while read line
do
field1=`echo $line| awk {'print $1'}
field2=`echo $line| awk {'print $2'}
line=`printf ${field1}${field2}`
echo $line >> newfile
done
hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 08:32 AM
06-10-2005 08:32 AM
Re: Awk/ GAWK Help Requested: How to get the space out of my lines
awk '{print $1$2}'
Will smash the first and second fields together.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 08:41 AM
06-10-2005 08:41 AM
Re: Awk/ GAWK Help Requested: How to get the space out of my lines
awk '{if (NR >= 5) { print $1$2 } else { print $0}}' yourfile >resultfile
Where the 5 in the NR >= 5 is the line number you require. Do you need to print the rest of the line (everything after $1 and $2) on the lines you merge?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2005 09:17 AM
06-10-2005 09:17 AM
Re: Awk/ GAWK Help Requested: How to get the space out of my lines
# awk '{if($1~"work") print $1$2; else print $0}' infile > outfile
this approach preserves the entire input file while gluing only the matched line.
enjoy!