awk command to return only field with a number in it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk command to return only field with a number in it
# 1  
Old 06-26-2016
awk command to return only field with a number in it

What is an awk command to print only fields with a number in it??

Input file.......
Code:
S,S,S,S,S,S,S,S,S
001S,S,S,S,S,S,S,S,S
00219S,23S,24S,43S,47S,S,S,S,S
00319S,10S,23S,41S,43S,47S,S,S,S
00423S,41S,43S,46S,47S,S,S,S,S
00510S,23S,24S,43S,46S,S,S,S,S
00610S,23S,43S,46S,47S,S,S,S,S
00743S,46S,10S,23S,42S,47S,S,S,S

And as an output I want

Code:
001S
00219S,23S,24S,43S,47S,
00319S,10S,23S,41S,43S,47S
00423S,41S,43S,46S,47S
00510S,23S,24S,43S,46S
00610S,23S,43S,46S,47S
00743S,46S,10S,23S,42S,47S

# 2  
Old 06-26-2016
Quote:
Originally Posted by garethsays
What is an awk command to print only fields with a number in it?? [...]
It would be more than just a command. Why does it have to be AWK, have you been working on it with AWK, already? What have you tried? Where are you having problems with?
# 3  
Old 06-26-2016
In addition to showing us what you have tried to solve your problem, please also explain in more detail why most alphabetic fields are deleted, but one of the alphabetic fields at the end of the 3rd input line (2nd output line) in your samples was converted to an empty field (with the trailing comma)???

What should happen if there is a leading alphabetic field in your input file followed by a field that contains a numeric character. Should there be a leading comma in the output or not?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - Print column number that return value comes from

I have the following awk script that I am using to find the max value in the file and print results. awk 'BEGIN {MAX=-1E100} {for (x=2; x<=NF; x++) if ($x>MAX) {MAX = $x; C1 = $1}} END {print substr(C1,1,11), substr(C1,13,4), substr(C1,18,2), MAX}' ABC* Input (ABC*) ... (6 Replies)
Discussion started by: ncwxpanther
6 Replies

2. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

3. Shell Programming and Scripting

awk return number of entries

I have a string with the following information and want to return the number of entries enclosed by <> in awk <stdin>: N = 441 <0.369000018/0.569000006> <0.369000018/0.569000006> <0/1> (7 Replies)
Discussion started by: kristinu
7 Replies

4. Shell Programming and Scripting

Awk to remove carriage return from 65th field

Hi, I have a pipe delimited file. There are around 700 columns in the file. The 65th column has carriage return which is causing read issue with our ETL process. I would like to replace the new line characters in 65th field with "nothing" i have return the following code and need help to... (7 Replies)
Discussion started by: pinnacle
7 Replies

5. Shell Programming and Scripting

awk script to return the middle line number

I need an awk script that returns the 1st field of the line in the middle of a file. For example, if a file I have has 6 lines, I want it to return the 1st field on line number 3. If a file has 7 lines, I want the script to return the 1st field on line number 4. File1: 3 214 4 219 5 226 2... (8 Replies)
Discussion started by: jontjioe
8 Replies

6. Shell Programming and Scripting

awk conditional expression to compare field number and variable value

Hi, I'm trying to compare the value in a field to the value in a variable using awk. This works: awk '$7 == "101"'but this is what I want (and it doesn't work): value=101 awk '$7 == "$value"' Any help or insight on this would be great. Thanks in advance. (1 Reply)
Discussion started by: goodbenito
1 Replies

7. Shell Programming and Scripting

awk to print exact field number

Hello there. I want some help with awk I have this script that reads a file from awk and you can insert from keyboard any list from the fields that exist so to be printed on monitor echo "give a choice" read -a ans array=${ans} awk -F: -v k="$array" '{ ... (4 Replies)
Discussion started by: covis
4 Replies

8. Shell Programming and Scripting

Diff Command to return the number of lines inserted,deleted and changed.

Hello, I have to compare two files file1 and file2, retrieve the number of lines modified (added, deleted or modified) in file2. Output must be like: File2: Added Deleted Changed Total ------ ------- -------- ----- 2 1 1 4 Somebody... (2 Replies)
Discussion started by: nmattam
2 Replies

9. Shell Programming and Scripting

doing rot13 on a field with a random number with awk

i have a several million line file like this: M:charitygeneral:water:fairbanks:charitygeneral field 2 and field 5 are the same i want to read the file and rot13 or any caesar cipher field 2 and replace the with a random number 1 - 9 anyone know how to do this? something slightly... (8 Replies)
Discussion started by: bathtub
8 Replies

10. Shell Programming and Scripting

use awk to aggregrate the field number

Hi, I have a various files;each filled with hundreds of line with similar number of fields. I would like to extract out field $5 from each of this file and aggregate them before printing out to a file. I tried to :- #!/usr/bin/awk -f file="file1.txt file2.txt file3.txt file4.txt" ... (1 Reply)
Discussion started by: ahjiefreak
1 Replies
Login or Register to Ask a Question