- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- perl, sed or awk
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
04-21-2005 02:57 PM
04-21-2005 02:57 PM
...
...
...
...
I need to get the "-" part to be replaced by a variable content using perl or sed or awk.
Maximum points for correct reply!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 03:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 04:14 PM
04-21-2005 04:14 PM
Re: perl, sed or awk
using sed
substitute (find & replace) "-" with "$" on each line
sed 's/â -â /â $â /' # replaces only 1st instance in a line
sed 's/â -â /â $â /4' # replaces only 4th instance in a line
sed 's/â -â /â $â /g' #
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 04:18 PM
04-21-2005 04:18 PM
Re: perl, sed or awk
Sorry about the font.
using sed
substitute (find & replace) "-" with "$" on each line
sed 's/"-"/"$"/' # replaces only 1st instance in a line
sed 's/"-"/"$"/4' # replaces only 4th instance in a line
sed 's/"-"/"$"/g' #
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 04:44 PM
04-21-2005 04:44 PM
Re: perl, sed or awk
As I'm not logged into a hp-ux system right now,
I can't test if '-' char as field separator needs to be
escaped or not (i.e -F- or -F\-).
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2005 10:17 PM
04-21-2005 10:17 PM
Re: perl, sed or awk
My attempt in awk...
$cat awkit
awk '
{
if ($1 == "
printf("
else
print $0
}' $1
if your file called foo then ...
$awkit foo my_variable
however I must admit that if your variable has spaces in then it doesn't work! i.e.
$awkit foo "my variable"
bombs out I guess you could add $3 to the script to fix - but there must be a better way
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2005 12:17 AM
04-22-2005 12:17 AM
Re: perl, sed or awk
this will do an in-place edit of the file & save the original to *.org
You obviously need to say what somethinghere is.
Assume you want to replace "somethinghere" with something like mod 4 subid1 them
perl -i.org -ane 'if (m/[0-9]+\"\-\"[0-9]/) { ($id1,$id2)=split /\"-"/; $somethinghere=$id1%4; print "$id1 $somethinghere $id2";} else { print "@F\n";}'
Regards
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2005 12:19 AM
04-22-2005 12:19 AM
Re: perl, sed or awk
I think I found a way to use sed for this purpose.
I created a file by name test1.
$ cat test1
wrote a small script:
---------------------------------------
rep=AAAA #Let the replacement be AAAA
rep_string="s/-/$rep/g" # Replace string built to be used by sed(1).
sed $rep_string test1 # Pass rep_string to sed(1).
Output (on Linux and HP-UX):
------------------------
Hope this helps and I get maximum point ;-)
Cheers,
Anupam Anshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2005 08:51 PM
04-23-2005 08:51 PM
Re: perl, sed or awk
perl -pi.org -e 's/(
No need to get overly complicated *shrug*.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 02:59 AM
04-24-2005 02:59 AM
Re: perl, sed or awk
For *exactly* a "dash" ("-") as you stated) use:
------------------------------------------
# f=/tmp/file
# cat $f # already has data in it
aa
cc
dd
# tf=/tmp/ff
# newtext='hohoho'
# sed < $f > $tf \
-e '/
# cp $tf $f
# cat $f
aa
cc
dd
------------------------------------------
For *anything* between the original double quotes:
------------------------------------------
# tf=/tmp/ff
# f=/tmp/file
# newtext='hehehe'
# sed < $f > $tf \
-e '/
# cp $tf $f
# cat $f
aa
cc
dd
HTH
bv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 01:11 PM
04-24-2005 01:11 PM
Re: perl, sed or awk
cat test.pass|awk -F- '{printf("%s Variable %s\n",$1,$2)'}
NOTE:$1,$2 is column order in your file
HTH
tienna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2005 02:08 PM
04-24-2005 02:08 PM
Re: perl, sed or awk
Many thanks for your replies. It was a great help!