- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Need help with awk/cut script please, formating co...
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-26-2006 11:27 AM
тАО04-26-2006 11:27 AM
Need help with awk/cut script please, formating columns
I have data that is formated in columns that looks like the following(note the example data is actaully one full line the web page has wrapped it).
11AF: 10A:1/myhost/0_3_0 10A:1/myhost/0_6_1 7A:1/myhost/0_9_0 7A:1/myhost/0_2_1
The / tend to confuse the shell and i have characaters :, /, and space as delimiters on the same line which is making it tough to put the data into proper format. I do not have control over the input format just as a fyi.
The output format I am trying to get to using the above line example is as follows (the following is on one line as well):
11AF 10A 1 myhost 0_3_0 10A 1 myhost 0_6_1 7A 1 myhost 0_9_0 7A 1 myhost 0_2_1
I am trying to get the flow to work like.
for i in `cat list`
do
each formated line above is equal to a variable.
example a=11AF b=10A c=1 and so on.
This way i can generate commands line by line in with the specific variables and order with syntax in between very easily.
Example command -someoption $b -anotheroption $a
Many Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2006 11:45 AM
тАО04-26-2006 11:45 AM
Re: Need help with awk/cut script please, formating columns
Perl will handle multiple characters as delimiters.
# X='11AF: 10A:1/myhost/0_3_0 10A:1/myhost/0_6_1 7A:1/myhost/0_9_0 7A:1/myhost/0_2_1'
# echo ${X}|perl -nle '@a=split /[:\/]/;print "@a"'
11AF 10A 1 myhost 0_3_0 10A 1 myhost 0_6_1 7A 1 myhost 0_9_0 7A 1 myhost 0_2_1
If this is what you want, do:
# perl -nle '@a=split /[:\/]/;print "@a"'
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2006 08:16 PM
тАО04-26-2006 08:16 PM
Re: Need help with awk/cut script please, formating columns
Its very simple. Use the following
cat filename | sed -e "s/:/ /g" -e "s/\// /g"
Regards,
Ninad
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2006 08:36 PM
тАО04-26-2006 08:36 PM
Re: Need help with awk/cut script please, formating columns
echo "11AF: 10A:1/myhost/0_3_0 10A:1/myhost/0_6_1 7A:1/myhost/0_9_0 7A:1/myhost/0_2_1" | tr '\:' " " |tr '\/' " "
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-26-2006 09:14 PM
тАО04-26-2006 09:14 PM
Re: Need help with awk/cut script please, formating columns
get rid of multiple delimiter and empty fields.
If you should need the original $@ after this processing, store the positional parameters into a differnt variable.
If your strings form lines in the file list:
typeset -i i n=0
sed 's,[:/], ,g' list |
while read line
do
((n+=1))
set $line
# processing as one unit
echo $line
# processing of the fields
for var
do
echo $var
done
# processing as a matrix
i=1
while [ i -le $# ]
do
eval print $n.$i \$$i
done
done
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2006 01:11 AM
тАО04-27-2006 01:11 AM
Re: Need help with awk/cut script please, formating columns
try the attached script, using your infile as $1
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2006 01:37 AM
тАО04-27-2006 01:37 AM
Re: Need help with awk/cut script please, formating columns
Perl's version of 'tr' will do this too, thusly:
# perl -nle 'tr /:\/ / /s;print' filename
[ Please copy-and-paste since the Forum is going to reduce the whitespace above ].
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2006 02:59 AM
тАО04-27-2006 02:59 AM
Re: Need help with awk/cut script please, formating columns
When confronted with this type of thing when I 've already got a working solution on one type of delimiter (as you do).
Have a pre-processing pass that will unify your delimiter to one type instead of two.
In your script before running your regular process:
cat file1 | sed -e "s/\//:/g" > file1.a
[The above changes backslashes to ":" - giving you a single delimiter that doesn't need escaping to process]
... continue on with your program reading "file1.a" instead of "file1" - using ":" as the delimiter for parsing your variables.
This is a "cheap" way out with the following obvious limitation: If the file you are parsing is HUGE, then the above solution may cost you too much time, in which case there are better previous postings to do it all it once.