Sponsored Content
Top Forums Shell Programming and Scripting AWK Script - Print a column - within a Row Range Post 302559811 by panapty on Wednesday 28th of September 2011 08:54:55 AM
Old 09-28-2011
Chubler_XL
Man that was awesome, It worked really cool.. Thanks again for your time and bearing with me this script!!!!
Saludos.

---------- Post updated at 07:54 AM ---------- Previous update was at 07:37 AM ----------

One more help, Last time I did not realize about some categories might display several times in the input file. For example, category BAOC, it has 4 occurrences, so I need to extract that category and the column beside called STATUS separated by commas

OUTPUT
Code:
67807532,714011000643614,OBO-0,OBR-2,OBI-0,TS21-1,OICK-24,TICK-11,1,2

Input File
Code:
hgsdp:msisdn=50767807532,all;
HLR SUBSCRIBER DATA
SUBSCRIBER IDENTITY
MSISDN           IMSI             STATE          AUTHD
50767807532      714011000643614  CONNECTED      AVAILABLE
NAM
0
PERMANENT SUBSCRIBER DATA
SUD
CAT-10       DBSG-1       TSMO-0       OBR-2
OSB4-1       TS11-1       TS21-1       TS22-1
BS2G-1       BS3G-1       REDMCH-1     OFA-1
PWD-0000     EMLPP-1      DEMLPP-5     MEMLPP-5
OICK-24      TICK-11      CFU-1        BAOC-1
BOIC-1       BOIEXH-1     BAIC-1       BICRO-1
CAW-1        SOCFU-0      SOCB-1       SOCLIP-0
SODCF-0      SOSDCF-7     HOLD-1       MPTY-1
CLIP-1       RED-1
SCHAR-8-0
SUPPLEMENTARY SERVICE DATA
BSG
TS10
SS       STATUS        FNUM                 TIME
                       SADD
BAIC     NOT ACTIVE
BAOC     NOT ACTIVE
BSG
TS20
SS       STATUS        FNUM                 TIME
                       SADD
BAIC     NOT ACTIVE
BAOC     NOT ACTIVE
BSG
BS20
SS       STATUS        FNUM                 TIME
                       SADD
BAIC     NOT ACTIVE
BAOC     NOT ACTIVE
BSG
BS30
SS       STATUS        FNUM                 TIME
                       SADD
BAIC     NOT ACTIVE
BAOC     NOT ACTIVE

Script
Code:
BEGIN { RS="hgsdp" }
{   cat[1] = "OBO"
    cat[2] = "OBR"
    cat[3] = "OBI"
    cat[4] = "TS21"
    cat[5] = "BAOC"
}
{
    if ($12 ~ /NOT/ ) printf "\n" substr ($1,16,8) "," "NOT_CONNECTED" ;
    else printf "\n" substr ($1,16,8) "," $12
}
{
    for (x = 1; x <= 5; x++)
    if (match($0,cat[x])) printf "," substr($0, RSTART, RLENGTH+2)
    else { printf "," cat[x]"-0" }
    if (match($0,"OICK")) printf "," substr($0, RSTART, RLENGTH+3)
    if (match($0,"TICK")) printf "," substr($0, RSTART, RLENGTH+3)
    if (match($0,"PACKET.*END")) { A=substr($0, RSTART, RLENGTH)
     while(match(A, "\n *[0-9]+ ")) {
         V=substr(A, RSTART+1, RLENGTH-2)
         sub(/^ */, ",",V)
         printf V
         A=substr(A,RSTART+RLENGTH+1)
     }
 }
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

append column and row header to a file in awk script.

Hi! Is there a way to append column and row header to a file in awk script. For example if I have Jane F 39 manager Carlos M 40 system administrator Sam F 20 programmer and I want it to be # name gend age occup 1 Jane F 39 manager 2 Carlos M ... (4 Replies)
Discussion started by: FUTURE_EINSTEIN
4 Replies

2. Shell Programming and Scripting

Print unique names in each row of a specific column using awk

Is it possible to remove redundant names in the 4th column? input cqWE 100 200 singapore;singapore AZO 300 400 brazil;america;germany;ireland;germany .... .... output cqWE 100 200 singapore AZO 300 400 brazil;america;germany;ireland (4 Replies)
Discussion started by: quincyjones
4 Replies

3. Shell Programming and Scripting

awk - script help: column to row format of data allignment?

Experts Good day, I have the following data, file1 BRAAGRP1 A2X B2X C2X D2X BRBGRP12 A3X B3X Z10 D09 BRC1GRP2 LO01 (4 Replies)
Discussion started by: rveri
4 Replies

4. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 Replies

5. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

6. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

7. Shell Programming and Scripting

Print row on 4th column to all row

Dear All, I have input : SEG901 5173 9005 5740 SEG902 5227 5284 SEG903 5284 5346 SEG904 5346 9010 SEG905 5400 5456 SEG906 5456 5511 SEG907 5511 9011 SEG908 5572 9015 SEG909 5622 9020 SEG910 5678 5739 SEG911 5739 5796 SEG912 5796 9025 ... (3 Replies)
Discussion started by: attila
3 Replies

8. Shell Programming and Scripting

awk script row to column

Hi.. I have data : Report testing1 20180419 08:00 Report testing2 20180419 07:35 Report testing 20180419 08:01 Source = data1 Report testing4 20180419 08:05 Source = data1 Report testing5 20180419 08:10 Source = data2 Report testing6 20180419 08:01 Report testing7 20180419 08:19... (4 Replies)
Discussion started by: buncit8
4 Replies

9. Shell Programming and Scripting

Need awk or Shell script to compare Column-1 of two different CSV files and print if column-1 matche

Example: I have files in below format file 1: zxc,133,joe@example.com cst,222,xyz@example1.com File 2 Contains: hxd hcd jws zxc cst File 1 has 50000 lines and file 2 has around 30000 lines : Expected Output has to be : hxd hcd jws (5 Replies)
Discussion started by: TestPractice
5 Replies

10. UNIX for Beginners Questions & Answers

Script to do column to row in awk

Hi , Can anyone help me suggesting - how to do the below trick with awk Input 120 130 140 210 310 410 645 729 800 Output 120 130 140 (6 Replies)
Discussion started by: Indra2011
6 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 07:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy