awk : Remove column1 and last column in a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk : Remove column1 and last column in a line
# 1  
Old 05-05-2011
awk : Remove column1 and last column in a line

Hi All,

How to remove col1 and last column in a line. Please suggest some awk stuffs.

Input
Code:
col1 col2 col3 col4
col1 col2 col3 col4 col5 
col1 col2 col3 col4
col1 col2 col3

Output
Code:
Processing col2 col3 ...
Processing col2 col3 col4  ...
Processing col2 col3 ...
Processing col2  ...

Thanks,
Mani Muthu
# 2  
Old 05-05-2011
Code:
awk -F' ' '{printf "processing "; for(i=2;i<NF;i++){ printf "%s ",$i}; print "..."}' file_name

# 3  
Old 05-05-2011
Code:
awk '{NF=NF-1;$1=$1;sub(".*"$2,$2,$0)}1' infile

use nawk instead of awk if running on SunOS / Solaris plateform
# 4  
Old 05-05-2011
thanks for your solutions. How to store the col2 to col n-1 in a variable
# 5  
Old 05-05-2011
What is your final goal ?

Code:
awk '{NF=NF-1;$1=$1;sub(".*"$2,$2,$0);print "Processing",$0}' infile

# 6  
Old 05-05-2011
I am trying to extract .rar format files in solaris.
I am using the a utility to extract the files.
While I am extracting a rar file it shows the below message
Code:
Extracting  folder1/folder 2/file OK

Insist of the above message I want to show the below message
Code:
 
Processing folder1/folder 2/file ...

Suppose a path having some space, then $2 getting the partial path name only.
I want to show the full path name.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

CSV File:Filter duplicate records from column1 & another column having unique record

Hi Experts, I have csv file with 30, 40 columns Pasting just 2 column for problem description. Need to print error if below combination is not present in file check for column-1 (DocumentNumber) and filter columns where value in DocumentNumber field is same. For all such rows, the field... (7 Replies)
Discussion started by: as7951
7 Replies

2. Shell Programming and Scripting

How can I remove first column with awk?

cat input.txt a x b y c z Expected output x y z (11 Replies)
Discussion started by: cola
11 Replies

3. Shell Programming and Scripting

How to remove a line based on contents of the first column?

Good day all. Using basic UNIX/Linux tools, how would you delete a line based on a character found in column 1? For example, if the CITY name contains an 'a' or 'A', delete the line: New York City; New York Los Angeles; California Chicago; Illinois Houston; Texas Philadelphia;... (3 Replies)
Discussion started by: BRH
3 Replies

4. Shell Programming and Scripting

Remove character from a column in each line

Hi, I am a newbie to shell scripting (.sh). Please guide me on how to do the below issue. My input file has below data. I want to remove $ sysmbol from the fourth column of each line. (ie, between 4th and 5th pipe symbol) ABC25160|51497|06/02/2010|$32,192.07|MARK|$100|A... (3 Replies)
Discussion started by: rsreejithmenon
3 Replies

5. Shell Programming and Scripting

How to remove a line if column 1 does not contain any value?

Input File science maths tom 2 3 peter 5 rodger 5 7 Desired Ouput science maths tom 2 3 rodger 5 7 Here Peter does not have any value for column Science, how can we delete Peter's row. assuming this is abc.txt file; and am using bash... (8 Replies)
Discussion started by: vishalgoyal
8 Replies

6. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, i have a csv file . In the 7th column i have data that has line feed in it. Requirement is to remove the line feed from the 7th column whenever it appears There are 11 columns in the file C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11 The value in C7 contains line feed ( Alt + Enter ),... (2 Replies)
Discussion started by: r_t_1601
2 Replies

7. Shell Programming and Scripting

Remove line feed from csv file column

Hi All, My requirement is to remove line (3 Replies)
Discussion started by: r_t_1601
3 Replies

8. Shell Programming and Scripting

awk - replacing stings in file1 with column1 in file2

Hello, I've never used awk before, but from what I've read, it will best suit what I'm trying to do. I have 2 files. I need to replace strings in file1 with the first column of a matching string in file2. Below are examples: File1: random-string1 1112 1232 3213 2131 random-string2... (7 Replies)
Discussion started by: upstate_boy
7 Replies

9. Shell Programming and Scripting

awk remove column with conditions?

Folks: I have a file which has 3 columns. Using awk I want to remove rows from column 3 (Col3 <> A) where it is not equal to A. All columns are seperated by "|". Col1|Col2|Col3|Col4 1 | 2 | A | 4 2 | 3 | A | 5 3 | 4 | B | 6 4 | 5 | A | 7 5 | 6 | ... (3 Replies)
Discussion started by: pr2003
3 Replies

10. Shell Programming and Scripting

remove new line characters from a partcular column data

Dear friends, I have a pipe delimited file having 5 columns. However the column no-3 is having extra new line characters as the data owing to owing , I am having issues. Ideally my file should have only newline termination at the end of each record and not within column data of any of... (1 Reply)
Discussion started by: sureshg_sampat
1 Replies
Login or Register to Ask a Question