Sponsored Content
Full Discussion: transpose based on condition
Top Forums Shell Programming and Scripting transpose based on condition Post 302360895 by danmero on Sunday 11th of October 2009 09:40:03 AM
Old 10-11-2009
Quote:
Originally Posted by aemunathan
The script is
Code:
#!/bin/ksh
/usr/xpg4/bin/awk -F"-"  '{print $2,$4}' /aemu/ErrorLogs/data/MissingCGIcount.txt | /usr/xpg4/bin/awk -F" " '{print $1,$3}' > /aemu/
ErrorLogs/data/MissingCGIcount_mnc.txt 
sleep 3
/usr/xpg4/bin/awk -F" " '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}' /aemu/ErrorLogs/data/MissingCGIcount_mnc.txt

Wow , what's that ? 3 time awk ? somethig like:
Code:
awk -F"-"  '{print $2,$4}' file | awk -F" " '{print $1,$3}' | awk -F" " '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}'

Your logic using awk only once.
Code:
awk -F"[- ]" '{arr[$2]+=$NF} END {for (i in arr) {print i,arr[i]}}' file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to split the String based on condition?

hi , I have a String str="/opt/ibm/lotus/ibw/latest" or ="/opt/lotus/ibw/latest" this value is dynamic..I want to split this string into 2 strings 1. /opt/ibm/lotus(/opt/lotus) this string must ends with "lotus" 2./ibw/latest can any body help me on this? Regards, sankar (2 Replies)
Discussion started by: sankar reddy
2 Replies

2. Shell Programming and Scripting

Merging of all files based on a condition

Hi Friends, I am new to UNIX. I need to merge all the files(to FINAL.txt) in single directory based one condition. Out of all the files one of file will have specific value like :GF01: at any where in the file. so the file which is having :GF01: should be appended at the last. EX:... (5 Replies)
Discussion started by: arund_01
5 Replies

3. Shell Programming and Scripting

Condition based concatenation.

Hello, I am looking for concatenating the lines based on conditions. Below are the contents of the file: Infile: ----- Test1.PO_Itm COLUMN GAC_DT. Test1.PO_Itm COLUMN (PRODTCD ,PLNTCD). Test1.PO_Itm COLUMN PLNTCD. Test1.PO_Itm COLUMN ACTVIND. Test2.RgnToTerrtryGPI COLUMN... (3 Replies)
Discussion started by: indrajit_u
3 Replies

4. Shell Programming and Scripting

Comment based on a condition

I want to comment 2 lines based on a condition. If THEN occurs immediately after WHEN then i have to comment both the lunes For example : $cat file1.txt CASE WHEN THEN 1 WHEN c1= 'I' AND c2= '0' THEN 2 So in this example i want to... (2 Replies)
Discussion started by: ashwin3086
2 Replies

5. UNIX for Dummies Questions & Answers

moving files based on condition

hi i have to move files and send an email and attached the bad files to inform the developer about that. #!/bin/ksh BASE_DIR=/data/SrcFiles cd $BASE_DIR ## finding the files from work directory which are changed in 1 day find -type f -name "*.csv" –ctime 0 > /home/mydir/flist.txt ##... (14 Replies)
Discussion started by: awais290
14 Replies

6. Shell Programming and Scripting

Transpose timestamp based on column values and calculate time difference

Hello Expert, I need to transpose Date-Timestamp based on same column values and calculate time difference. The input file would be as below and required output is mentioned in the bottom INPUT File ======== 08/23/2012 12:36:09 JOB_5340 08/23/2012 12:36:14 JOB_5340 08/23/2012... (2 Replies)
Discussion started by: asnandhakumar
2 Replies

7. Shell Programming and Scripting

Columns to Rows - Transpose - Special Condition

Hi Friends, Hope all is well. I have an input file like this a gene1 10 b gene1 2 c gene2 20 c gene3 10 d gene4 5 e gene5 6 Steps to reach output. 1. Print unique values of column1 as column of the matrix, which will be a b c (5 Replies)
Discussion started by: jacobs.smith
5 Replies

8. UNIX for Dummies Questions & Answers

Condition based on Timestamp (Date/Time based) from logfile (Epoch seconds)

Below is the sample logfile: Userids Date Time acb Checkout time: 2013-11-20 17:00 axy Checkout time: 2013-11-22 12:00 der Checkout time: 2013-11-17 17:00 xyz Checkout time: 2013-11-19 16:00 ddd Checkout time: 2013-11-21 16:00 aaa Checkout... (9 Replies)
Discussion started by: asjaiswal
9 Replies

9. Shell Programming and Scripting

Transpose matrix based on second column using awk

Hi, Is it possible to transpose the matrix like this using awk ? Many thanks in advance Input abc Name_1 0 abc Name_2 1 abc Name_3 2 abc Name_4 0.4 def Name_1 0 def Name_2 9 def Name_3 78 def Name_4 1 Output abc def Name_1 0 ... (4 Replies)
Discussion started by: quincyjones
4 Replies

10. Shell Programming and Scripting

Copy down based on condition

Hello: I need to copy down some data from the previous record in to the next record based on the below conditions If position 41- 59 of the current record is same as the previous record and the value of position 62 is not equal to 1 then copy the previous records value for positions... (1 Reply)
Discussion started by: techedipro
1 Replies
NPM-RUN-SCRIPT(1)														 NPM-RUN-SCRIPT(1)

NAME
npm-run-script - Run arbitrary package scripts SYNOPSIS
npm run-script <command> [--silent] [-- <args>...] alias: npm run DESCRIPTION
This runs an arbitrary command from a package's "scripts" object. If no "command" is provided, it will list the available scripts. run[-script] is used by the test, start, restart, and stop commands, but can be called directly, as well. When the scripts in the package are printed out, they're separated into lifecycle (test, start, restart) and directly-run scripts. As of ` https://blog.npmjs.org/post/98131109725/npm-2-0-0, you can use custom arguments when executing scripts. The special option -- is used by getopt https://goo.gl/KxMmtG to delimit the end of the options. npm will pass all the arguments after the -- directly to your script: npm run test -- --grep="pattern" The arguments will only be passed to the script specified after npm run and not to any pre or post script. The env script is a special built-in command that can be used to list environment variables that will be available to the script at run- time. If an "env" command is defined in your package, it will take precedence over the built-in. In addition to the shell's pre-existing PATH, npm run adds node_modules/.bin to the PATH provided to scripts. Any binaries provided by locally-installed dependencies can be used without the node_modules/.bin prefix. For example, if there is a devDependency on tap in your package, you should write: "scripts": {"test": "tap test/*.js"} instead of "scripts": {"test": "node_modules/.bin/tap test/*.js"} to run your tests. The actual shell your script is run within is platform dependent. By default, on Unix-like systems it is the /bin/sh command, on Windows it is the cmd.exe. The actual shell referred to by /bin/sh also depends on the system. As of ` https://github.com/npm/npm/releases/tag/v5.1.0 you can customize the shell with the script-shell configuration. Scripts are run from the root of the module, regardless of what your current working directory is when you call npm run. If you want your script to use different behavior based on what subdirectory you're in, you can use the INIT_CWD environment variable, which holds the full path you were in when you ran npm run. npm run sets the NODE environment variable to the node executable with which npm is executed. Also, if the --scripts-prepend-node-path is passed, the directory within which node resides is added to the PATH. If --scripts-prepend-node-path=auto is passed (which has been the default in npm v3), this is only performed when that node executable is not found in the PATH. If you try to run a script without having a node_modules directory and it fails, you will be given a warning to run npm install, just in case you've forgotten. You can use the --silent flag to prevent showing npm ERR! output on error. You can use the --if-present flag to avoid exiting with a non-zero exit code when the script is undefined. This lets you run potentially undefined scripts without breaking the execution chain. SEE ALSO
o npm help 7 scripts o npm help test o npm help start o npm help restart o npm help stop o npm help 7 config January 2019 NPM-RUN-SCRIPT(1)
All times are GMT -4. The time now is 08:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy