- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: add line number file (combination with xargs)
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
тАО11-22-2010 07:02 AM
тАО11-22-2010 07:02 AM
i have following questions :
- what is the fastest (or easiest) way to add at the begin of file the line number ?
my solutions :
awk '{ print $NR,$0 }' file > file_temp
or
nl -w1 -s" " file > file_temp
and
mv file_temp file
better solutions ?
- how to change this part of a shell script :
xargs -l -x ./sub_prog < xargs_params_file
to
- i want to add a the begin of "xargs_params_file" the line number
i think i can only do this to modify "xargs_params_file" ? a combination is possible
best regards,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2010 07:19 AM
тАО11-22-2010 07:19 AM
Re: add line number file (combination with xargs)
Either of your solutions to add a line number works. In order to eliminate the manual move of the updated file, you could use Perl:
# perl -ni.old -e 'print "$. $_"' myfile
...which performs an inplace update and preserves a copy of the original file as "*.old".
As for your second question, if I understand correctly you could do something like:
# nl xargs_parms_file|cat -- - myfile
Note the '--' to signal the end of any options and a '-' to denote STDIN.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2010 10:56 AM
тАО11-22-2010 10:56 AM
Re: add line number file (combination with xargs)
>Note the '--' to signal the end of any options and a '-' to denote STDIN.
I'm not sure why you would want to use an evil cat? And cat(1) accepts the "-" without the "--".
Note: You need to read the documentation for nl(1) carefully. By default it won't number empty lines, so you need to add -ba.
- Tags:
- evil cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-22-2010 11:19 PM
тАО11-22-2010 11:19 PM
Re: add line number file (combination with xargs)
thank's for this solution
>> xargs -l -x ./sub_prog < xargs_params_file
maybe i explained it not so clear. in "xargs_params_file" are different entries (sep. " ") in each line and i don't know how many lines will exist in "xargs_params_file". for a change in "./sub_prog" in want to add as first parameter the line number of "xargs_params_file".
so i think i have to change "xargs_params_file" ?
or a combination of shell command's can solve this case ?
so
>> nl xargs_parms_file|cat -- - myfile
solve
>> xargs -l -x ./my_shell_sub_programm < xargs_params_file
??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-23-2010 12:00 AM
тАО11-23-2010 12:00 AM
Solution>I think I have to change "xargs_params_file"?
Yes, you can use nl(1) to number each line and have sub_prog use that first argument
>> nl xargs_parms_file|cat -- - myfile
>solve
>> xargs -l -x ./my_shell_sub_programm < xargs_params_file
You could do:
nl -ba xargs_parms_file | xargs -l -x ./my_shell_sub_programm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-03-2010 01:13 AM
тАО12-03-2010 01:13 AM
Re: add line number file (combination with xargs)
perfect,perfect. thx a lot.
sorry for my delayed answer.