Sponsored Content
Full Discussion: Cut or awk in reverse
Top Forums Shell Programming and Scripting Cut or awk in reverse Post 302521768 by maverick72 on Thursday 12th of May 2011 08:02:03 AM
Old 05-12-2011
Quote:
Originally Posted by mirni
Code:
$ echo 'PackageName-U939393-8.2.3.4.s390x.rpm' | awk -F. '{NF-=2;}1' OFS='.'
PackageName-U939393-8.2.3.4

NF is an internal variable that specifies Number of Fields. You can then access the last field as $NF, second to last as $(NF-1) etc.
Here I just decrement NF by two and set the OFS (output field separator) to '.'. The '1' is a shortcut for 'print $0'.
Just for my personnal comprehension ... got the 1 part but not the ; in the {NF-=2;} Can somebody expain? Cause it works without it.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How reverse cut or read rows of lines

Hi, My records are like this BSC403_JAIN03|3153_TropicalFarm_LIMJM1-3_97| BSC403_JAIN03|3410_PantaiAceh_PCEHM1_4_97| BSC406_BMIN02|1433_JomHebohTV3_COW7M1_11_97| I want to extract the value before _97| This command BSC_ID=`echo $DATA | cut -f5 -d"_"` gives me _97|, 4, 11 and by... (16 Replies)
Discussion started by: doer
16 Replies

2. Shell Programming and Scripting

[grep awk cut] > awk

Hi, I'm very new to scripting. grep $s $filename | awk '{print $2}' | cut -c 1-8 How can I optimize this using a single awk? I tried: awk '/$s/ {print $2}' $filename | cut -c 1-8 However didn't work, I think the awk is not recognizing $s and the verbal is something else. (6 Replies)
Discussion started by: firdousamir
6 Replies

3. Shell Programming and Scripting

reverse search in awk script

Hi, I am new to awk. Actually I want to search a pattern A, when I get that line with pattern A then for one of the field of that line again I want search on that field (say pattern B)from start of the file. I am using awk. Is nested searching possible in awk? Please do the needful as... (4 Replies)
Discussion started by: id4forum
4 Replies

4. Shell Programming and Scripting

awk, shell script reverse engineering app generator - project

Hi, this is fantastic forum for shell programming and scripting, so please let me to introduce you with my very old concept to have web form/s with radio, select, input fields and have an application generating valid, syntax error free scripting code. The same or alike questions are asked... (2 Replies)
Discussion started by: darius2
2 Replies

5. Shell Programming and Scripting

cut a field, but with reverse order

Hi Everyone, I have one a.txt: a b 001 c b b 002 c c c, not 002 c The output should be 001 002 002 If i use cut -f 3 -d' ', this does not work on the 3rd line, so i thought is any way to cut the field counting from the end? or any perl thing can do this?:confused: ... (3 Replies)
Discussion started by: jimmy_y
3 Replies

6. Shell Programming and Scripting

CUT command delimiter in reverse

Hi, I've a situation where, a=xxx.yyy.zzz.txt EXTN=`echo $a | cut -d . -f2` Using the above code it delimites and will return "yyy.zzz.txt" to EXTN. But i need to get only the extension "txt". so as per the above code it delimits in the first "." itself. Can anyone help how to do... (6 Replies)
Discussion started by: skcvasanth
6 Replies

7. Shell Programming and Scripting

Reverse script usage -Awk

Is it possible to convert EXONtoBED (Output to input)? 1. BEDtoExon.sh ------------------- awk '{ n11 = split($11, t11, ",") n12 = split($12, t12, ",") for (i = 0; ++i < n11;) { s12 = $2 + t12 print $1, s12, s12 + t11, i”E_”$4 } }' $1 ... (1 Reply)
Discussion started by: quincyjones
1 Replies

8. Shell Programming and Scripting

Help with sed/awk for reverse search and print

I have a file which is DFDG START DSFDS DSDS XXX END (VIO) AADD START SDSD FGFG END and I have to print the lines between START and END (VIO). In the files there are multiple places where START would be followed by END with few lines in between but I need to print only if START is... (18 Replies)
Discussion started by: pgbuddy
18 Replies

9. Shell Programming and Scripting

awk reverse string

Hello, Can anyone explain for me in this script to reverse the string? 1) the "x=x" part, how it works? $ echo welcome | awk '{ for(i=length;i!=0;i--)x=x substr($0,i,1);}END{print x}' $ emoclew2) x seems to be an array at the END, but can it automatically print the whole array in awk? Thanks... (8 Replies)
Discussion started by: yifangt
8 Replies

10. UNIX for Dummies Questions & Answers

How to cut part of a string in reverse?

Hi, how to cut part of a string sing delimiter in reverse input file 1,2,st-pa-tr-01,2,3,4, 2,3,ff-ht-05,6,7,8 how can i obtain strings till st-pa-tr ff-ht i.e cutting the last part og string -01 and -05 Thanks & Regards Nivi edit by bakunin: changed thread title (typo) (3 Replies)
Discussion started by: nivI
3 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 02:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy