- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ksh help: to extract 2 words from every line i...
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
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
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
07-07-2014 02:02 PM - edited 07-07-2014 02:15 PM
07-07-2014 02:02 PM - edited 07-07-2014 02:15 PM
I have a lot of lines in a file, and all with following format:
host_name:/vol/v1/v2
I only wanted to extract "host_name" and "v1" from every line in the file, then put these two words into a output file "out_file".
then create a for loop to process these two words in "out_file".
can anybody please help me out, it'd be appreciated very much
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2014 08:25 PM
07-07-2014 08:25 PM
Re: ksh help: to extract 2 words from every line in a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2014 10:43 PM
07-07-2014 10:43 PM
Re: ksh help: to extract 2 words from every line in a file
You could do:
IFS_save=$IFS # save
IFS=":/"
while read name dummy vol v1 v2; do
echo $name $v1
done < in_file > out_file
IFS=$IFS_IFS # restore
>then create a for loop to process these two words in "out_file".
You could process these in the above while. Or you can create another while read with just the two fields.
No need to fiddle with IFS for this second while.
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 10:48 AM - edited 07-08-2014 11:15 AM
07-08-2014 10:48 AM - edited 07-08-2014 11:15 AM
Re: ksh help: to extract 2 words from every line in a file
Thank you all for the response. I have one follow-up.
while read filer path; do
/bin/scripx.sh -f $filer -v $path -a
done < ./output1
with this script, why in the end only one instance of /bin/scriptx.sh got excuted? I wanted to run same number of times as the number of lines in "output1" file.
Thank you again!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 11:25 AM
07-08-2014 11:25 AM
Re: ksh help: to extract 2 words from every line in a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 12:28 PM
07-08-2014 12:28 PM
Re: ksh help: to extract 2 words from every line in a file
First off, no, I did not put scriptx.sh under /bin, it is just an example. it is actually located somewhere else. the following script results in the same.
$ cat hv1.sh
#!/bin/sh
exec <./output1
while read filer path; do
./hv2.sh -f $filer -v $path -a
done
The cause of it is because that in-house script scriptx.sh (or ./hv2.sh in your case) takes quite some time to finish. I even put sleep 60 in the loop. It is still the same. I used exec < ./output1, it doesn't help.
output1 file is consists of multiple lines which contains filer-n and path-n, as you guessed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2014 04:03 PM
07-08-2014 04:03 PM
Re: ksh help: to extract 2 words from every line in a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2014 07:05 AM
07-09-2014 07:05 AM
Re: ksh help: to extract 2 words from every line in a file
#cat run_find
exec <./output1
while read filer path; do
/example/find_details.pl -f $filer -v $path -a
sleep 60
done
#cat output1
filer1 path1
filer2 path2
filer3 path3
...
filer180 path180
sorry for the confusion. Let me try it again.
The script "find_details.pl" is the perl script and it is to grab some volume information from about 180 NAS storages. It takes about > 1 mins to complete.
The issue is the script "run_find" only execute the "find_details.pl" on the first line of "output1", then exit out.
Hope I made myself clear this time. thank you very much for your patience.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2014 07:12 AM - edited 07-09-2014 07:15 AM
07-09-2014 07:12 AM - edited 07-09-2014 07:15 AM
Solution.../scripx.sh -f $filer -v $path -a
>why in the end only one instance of .../scriptx.sh got executed?
If your evil scriptx is also reading stdin, you'll lose input. You can fix this by:
.../scripx.sh -f $filer -v $path -a < /dev/null
Typically examples of this failing is use of telnet, ssh, remsh (without -n), etc. Or scummy C shell scripts.
http://h30499.www3.hp.com/t5/Languages-and-Scripting/telnet-script-while-read/m-p/5824797
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2014 05:34 AM
07-10-2014 05:34 AM
Re: ksh help: to extract 2 words from every line in a file
This is the answer I am looking for. Thank you !