Using sed inside system call in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using sed inside system call in awk
# 8  
Old 07-20-2016
Quote:
Originally Posted by Yoda
Another approach:-
Code:
awk '/[^/]+/{sub(/\/$/,X)}1'

Hi Yoda, the / character needs to be escaped within an awk regex constant expression that is terminated by two slashes, even within a bracket expression:
Code:
awk '/[^\/]/{sub("/$",x)}1'


Quote:
Using a <slash> character within an ERE requires [the] escaping ...
awk: Regular Expressions



---
Other options:
Code:
sed 's|\(.\)/$|\1|'

Code:
perl -pe 's/(?<=.)\/$//'


Last edited by Scrutinizer; 07-20-2016 at 03:10 AM..
# 9  
Old 07-20-2016
Quote:
Originally Posted by Jcpratap
thanks

Code:
awk '/[^/]+/{sub(/\/$/,X)}1'

works

can you explain the same
/[^/]+/ - if record has one or more occurrence of any character other than / (to exclude root fs)

sub(/\/$/,X) - substitute or replace / in the end with X which is null or undefined variable.

1 - a non zero value or true, forces awk to print record.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed inside the awk script to replace a string in the array

The requirement is i need to find an array value matching with pattern {5:{ , replace that with 5: and reassign that to same array index and print it. I write something like below and the issue is sed command is not working. If i replace " with "`" the script gives syntax error.how can i... (8 Replies)
Discussion started by: bhagya123
8 Replies

2. Shell Programming and Scripting

awk statement piped inside sed

Hello folks, I have multiple occurrences of the pattern: ).: where is any digit, in various text context but the pattern is unique as this regex. And I need to turn this decimal fraction into an integer (corresponding percent value: the range of 0-100). What I'm doing is: cat... (1 Reply)
Discussion started by: roussine
1 Replies

3. UNIX for Dummies Questions & Answers

sed inside awk

What I want to do is delete everything upto the last underscore (_) in column 2. awk '{ $2=$(echo $2 | sed 's/.*_//'); print $0}' Sed works fine if I echo the string into it, this doesnt work inside awk. What am I doing wrong? Similarly, how do I store the substring starting with a... (4 Replies)
Discussion started by: senhia83
4 Replies

4. Shell Programming and Scripting

Invoking system(cmd) inside awk command

Hi, I was searching for a way to grep 2 lines before and after a certain keyword, and I came across the following code.. awk "\$0 ~ /ORA-/ { cmd=\"awk 'NR>=\" NR-2 \" && NR<=\" NR+2 \"' init.ora\" system(cmd) }" input_file I could not understand how this works. What is system() ? what... (2 Replies)
Discussion started by: Kulasekar
2 Replies

5. Shell Programming and Scripting

System call using awk on Solaris

I'm brand new to awk and need your help. I want to be able to shut down my workstations when they become to hot (because we've lost our cooling). I found a really neat way to monitor the temperature of the system and a short, simple awk scipt to use with it: /usr/sbin/prtpicl -v -c... (2 Replies)
Discussion started by: natural
2 Replies

6. Shell Programming and Scripting

Passing argument to system call in awk script

So, I have this script. It reads a CSV file that has a mixture of object names with IP addresses (parsing out that part I have working), and object names which have a DNS name. I want to be able to run a "dig +short" based off of the name given to me in the line of the awk script, and then deal... (6 Replies)
Discussion started by: mikesimone
6 Replies

7. Shell Programming and Scripting

Appending string (charachters inside the line) to a fixed width file using awk or sed

Source File: abcdefghijklmnop01qrstuvwxyz abcdefghijklmnop02qrstuvwxyz abcdefghijklmnop03qrstuvwxyz abcdefghijklmnop04qrstuvwxyz abcdefghijklmnop05qrstuvwxyz Whatever characters are in 17-18 on each line of the file, it should be concatenated to the same line at the character number... (6 Replies)
Discussion started by: tamahomekarasu
6 Replies

8. Shell Programming and Scripting

how to assign a value to several variables inside awk call

Hi I am using 'awk" to get file size and date of the file: op - sundev3 $ ls -l /bb/bin/tsfiles.sel | awk '{print $5 $6 $7}' 1587May8 May be somobody knows the way to combine this command with variable assignmet inside the awk, so I would have variables SIZE, MONTH and DATE assigned after... (1 Reply)
Discussion started by: aoussenko
1 Replies

9. UNIX for Advanced & Expert Users

how to differentiate system call from library call

Hi, Ho do I differentiate system call from library call? for example if I am using chmod , how do I find out if it is a system call or library call? Thanks Muru (2 Replies)
Discussion started by: muru
2 Replies

10. UNIX for Dummies Questions & Answers

a system call for sed in a awk script

Hi, this is my test file : DELETE FROM TABLE WHERE ID_INTERNAL = :TABLE.ID-INTERNAL, ID-INTERNAL-CRAZY ID-INTERNAL-OPEN ID-INTERNAL /ID-INTERNAL/ I want all occurences of ID-INTERNAL replaced with a one, if ID-INTERNAL has and dash afer it , dont replace it example:... (6 Replies)
Discussion started by: seaten
6 Replies
Login or Register to Ask a Question