- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- hp textfile adding index
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
тАО03-02-2006 06:16 PM
тАО03-02-2006 06:16 PM
Can you help me here.
I have a file having contents below
asdf
qwer
asff
and i want to add an index prompting what control number will I start so if i say 1 it will change output to
asdf 1
qwer 2
asff 3
so if i say start number is 125 it will have output like
asdf 125
qwer 126
asff 127
so that it automatically increases by one for each entry. I will be glad if you can help me using this with awk. thanks much.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2006 06:41 PM
тАО03-02-2006 06:41 PM
Re: hp textfile adding index
Try this
cat file.text |awk '{print $1 " " a+1; a++}'
asf 1
bfc 2
edr 3
wes 4
cat file.text |awk '{print $1 " " a+120; a++}'
asf 120
bfc 121
edr 122
wes 123
Indira A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2006 06:44 PM
тАО03-02-2006 06:44 PM
Re: hp textfile adding index
but a quick solution would be something like this:
#/sbin/sh
# script with passing parameter
typeset -i VAR
VAR=$1
cat yourfile |while read LINE
do
print "$LINE $VAR"
VAR=(($VAR + 1))
done
For a prompt you can add a read VAR
#/sbin/sh
# script with prompt
print "Type your control nr. here:\n"
typeset -i VAR
read VAR
cat yourfile |while read LINE
do
print "$LINE $VAR"
VAR=(($VAR + 1))
done
Many variations are possible,
but is the basic skeleton.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2006 07:00 PM
тАО03-02-2006 07:00 PM
Re: hp textfile adding index
I tried ff same but it give me error?
echo "enter start index \c"
read index
cat file | awk '{print $1 | $index+1;$index++}'
returns an error
awk: Field $() is not correct.
The input line number is 1.
The source line number is 1.
pls help
gives an error. Im pretty sure Im close its just that I need to get the clear use of variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2006 08:08 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-02-2006 08:08 PM
тАО03-02-2006 08:08 PM
Re: hp textfile adding index
awk dies not understand the $varibale as it is form the shell. May be use awk -v
I think if you need to be prompted for the index number then do as a script.
IA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-05-2006 08:23 PM
тАО03-05-2006 08:23 PM
Re: hp textfile adding index
using awk only (not cat is needed):
read b?"Start index "
awk 'BEGIN {B='''$b'''};{print $0 " " B++}' file
code in the BEGIN step assign to the AWK var B teh value of UNIX var b.
Rest of te code print the record in teh file plus the counter.
HTH,
Art