5

Using the shell command in awk does not work

 3 years ago
source link: https://www.codesd.com/item/using-the-shell-command-in-awk-does-not-work.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Using the shell command in awk does not work

advertisements

I have the following code in shell.

It does not work. So I don't know what's my mistake I was wondering if someone could help me

echo $i | awk -F "," '{if(NF == 1) print "Exiting..." system("exit")}'

so $i is a parameter for example hi,hello. And if the number of fields is equal to 1, I'd like the program to exit.


You cannot call exit through system, because awk is executed in a separate process. However, you can call exit from awk, with a specified error code, and then exit the script depending on the error code. Example:

awk -F "," '{if(NF==1){ print "Exiting"; exit -1}}' || exit

Related Articles

the convert command of imagemagick does not work properly in the php script but works from the command line

A system call to convert in php worked for years but quit working early this year. All commands that I am using work correctly if issued from the command line using Putty. A test php file I created to debug this is <? $string = "convert -verbose -

Using the lein project with / lib does not work

When using lein 2.2, trying to put jar files in /lib does not work. I tried and it doesn't seems to work but plenty of docs out there says this way still works.The lib directory functionality was removed in Leiningen v2.0, in favor of a repository (r

ButtonMode and using the HandCursor property in DataGrid does not work

If I set the properties of "buttonMode" and "useHandCursor" to true in DataGrid, it does not work as I expect. Only if I move the cursor to the edge between two rows, the hand cursor displayes. What I expect is that no matter where the

replace the string in the model using the shell command: sed, awk

Say I have a text file like this: a;bc;d;{a;b;cd} ab;cde;f;{ab;c;defg} ab;{a;b;cd};cde;f ... and I want to replace all the semicolons in curly brackets by comma. It will look like this after substitution: a;bc;d;{a,b,cd} ab;cde;f;{ab,c,defg} ab;{a,b,

MSIEXEC using the REINSTALL command line that does not use the original INSTALLDIR

I am trying to configure Wix to build my msi to only perform build versions (1.0.x) of my product in conjunction with the REINSTALL property, my problem is that when I run the command line: MSIEXEC.exe /i my.msi /l*vx build-inst.log REINSTALL=ALL REI

Passing shell settings to awk does not work

Why does this work for myfile in `find . -name "R*VER" -mtime +1` do SHELLVAR=`grep ^err $myfile || echo "No error"` ECHO $SHELLVAR done and outputs No error err ->BIST Login Fail 3922 err No error err ->IR Remote Key 1 3310 err

Running `find` using` std :: process :: Command` on cygwin does not work

When I try to call the find command from a Rust program, either I get a FIND: Invalid switch or a FIND: Parameter format incorrect error. find works fine from command line. echo $PATH /usr/local/bin:/usr/bin:/cygdrive/c/Windows/system32:/cygdrive/c/W

The phone state monitor using the broadcast receiver in Android does not work

I am trying to detect Incoming call using Broadcast Listener.Since I received one fault in my app when someone calls, my app still plays the song. So I want to pause song during Incoming Call. But I am not receiving any response. Here is the complete

Converting the Curl command to PHP does not work

I have curl command working through terminal and when I converts that command in PHP, it is giving me an error. Here is Curl command from terminal: [root@localhost ~]# curl -XPOST -v http://localhost:5636/api/1/event/AVyWHzgsJ-3JxxYdx60x/archive * Ab

E-mail validation using the regex expression in c # does not work in the c project

I am trying to validate emails according to the RFC 5322 standard. I have been using the following C# expression ^(?(")(".+?(?<!\\)"@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))(?(\[)(\[(\d{1,3}\.){3}\

Simple Java program using the same variable for input - does not work

All I want to do is use the string variable for all my scanner input. public static void main(String[] args){ Scanner getInput = new Scanner(System.in); String defaultInFile = "fileContainingEmails.txt"; String defaultOutFile = "copyPasteMy

Emulator-5554 offline! Cancellation of the 'launch of the activity'! I tried to solve with the cmd commands but still does not work

I am getting this error, I tried to resolve it but still it is not working.I have tried "adb kill-server" and adb start-server and also emulator -avd emulator_name -wipe-data. I have attached the screen shoot of cmd. I just want to run my applic

Using the Eclipse SimpleTest plugin - SimpleTest does not work

I'm using Eclipse 3.4.2 and installed the latest plug-in for simpletest using Help>Software Updates... The plugin installed correctly and I was able to set it up in Window>Preferences>SimpleTest. I have filled in the following fields : Php.exe fi

Using the variable & ldquo; Name & rdquo; Does not work with a JS object

The behaviour can be seen in this little snippet (execute it as a global script): var name = {}; name.FirstName = 'Tom'; alert(name.FirstName); The alert yields undefined in Chrome but works in IE and Firefox. I also get a weird value when I do alert

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK