0

Possible Duplicate:
problem in using awk

To be more specific, this is my project code

if [ "$FORMAT" = "java" ]; then
        cat $INPUT_FILE | awk -F":" '\
                /^$/ { print "" }\
                /^\/\/.*/ { print "     "$0}\
                /:string:/ { print "    public static final String "$1" = "$3";" }\
                /:char:/   { print "    public static final char "$1" = "$3";" }\

/:ullong:/ { print "    public static final long "$1" = "$3";" }\
                /:ulong:/  { print "    public static final int "$1" = "$3";" }\
                /:long:/   { print "    public static final int "$1" = "$3";" }\
        ' >> $CONST_FILE
fi;

Now i need to truncate $3 (this value is actually read from another file) into two parts(only for ullong). lets say

$3=1256985361455ULL

i need to truncate into 1256985361455 and ULL. (only when it is ullong) please help me out in this issue.

i tried using another awk inside the the following, but ended up in chaos.

/:ullong:/ { print "    public static final long "$1" = "$3";" }\
2
  • please go edit your previous post and add this information there. Commented Apr 19, 2011 at 12:57
  • awk tip: You do not need to cat the file. 'cat foo | awk ...' is best done with 'awk ... foo' Commented Apr 19, 2011 at 13:11

1 Answer 1

0

Are you saying that you just want to insert a space into $3? Just use sub:

bash-3.2$ cat input
one two 123456789ULL
one two 123456789UL
bash-3.2$ awk '{ sub( /ULL$/, " ULL", $3 ); print }' input
one two 123456789 ULL
one two 123456789UL
Sign up to request clarification or add additional context in comments.

2 Comments

hi.. not a space..i need to truncate ULL from the $3..
So make the replacement string empty. ie, sub( /ULL$/, "", $3 )

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.