edit each line in the file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers edit each line in the file
# 1  
Old 05-25-2007
edit each line in the file

I am trying to edit each line in a file. The file has several columns delimitted by '|'.
I need to take out the last two columns.
Each line starts with a unique word through which I am storing the lines in a variable and cutting the last two colums.
But, when I am echoing the line, it is printing each word of the line independently instead of the whole line.

The idea is to take off the last two columns and put back the file.

Please advise

Thanks
Chiru
# 2  
Old 05-25-2007
Code:
 awk '/^uniqword/{$0=$(NF-1)"|"$NF;print}' file

# 3  
Old 05-26-2007
Code:
sed 's/\(.*\)|\(.*\)|\(.*\)/\1/'  filename

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Edit first line of a text file

Hi friends, Issue1: I have a text file with the first line like this #chrom start end Readcount_A Normalized_Readcount_A ReadcountB Normalized_Readcount_B Fc_A_vs_B pvalue_A_vs_B FDR_A_vs_B Fc_B_vs_A pvalue_B_vs_A FDR_B_vs_A <a href="http://unix.com/">Link</a> How can I change it to the... (11 Replies)
Discussion started by: jacobs.smith
11 Replies

2. Shell Programming and Scripting

Edit a Huge one line file

We have a huge file which has just one really large line; about 500 MB. I want to 1. Count all the occurrences of a phrase 2. Replace the phrase with another. Trying to open it using vi has not helped as it complains that it is too large. Can any script help? Please advise. Thank you, (12 Replies)
Discussion started by: kaushikadya
12 Replies

3. Shell Programming and Scripting

up down arrow key and edit on command line.

I am using ksh, By doing change in .profile as set -o vi my updown and history does not work. Also I can not edit command line on prompt using vi command. My TERM is vt100. What is wrong here ? Thanks. :cool: (3 Replies)
Discussion started by: ekb
3 Replies

4. Shell Programming and Scripting

How to edit file to have one line entry?

Hello All, My file content is: DROP TABLE "FACT_WORLD"; CREATE TABLE "FACT_WORLD" ( "AR_ID" INTEGER NOT NULL, "ORG_ID" INTEGER NOT NULL ) DATA CAPTURE NONE COMPRESS YES; I want to change this file to have entries in one... (6 Replies)
Discussion started by: akash2508
6 Replies

5. Shell Programming and Scripting

Edit file content at the specific line.

How to edit file content at the specific line? For example at below The things to edit --> This is line 2. And it is below line 1. This is line 1. This is line 2. # i want to append some words at this row line. How? This is line 3. (8 Replies)
Discussion started by: alvin0618
8 Replies

6. Shell Programming and Scripting

edit a line for getting inputs

Hello Everybody, I have a file with data like this 8z:1 15y:0 7x:0 12w:1 ... ... I would like read each line through a loop and will needing to get the input from each line like this For 8z:1; a=8,b=1 15y:0; a=15,b=0 7x:0; a=7,b=0 Please let me know of a way to... (5 Replies)
Discussion started by: leo.maveriick
5 Replies

7. Shell Programming and Scripting

edit and add line

dear all, i need your help to change this input to output M9_3D_H10__Dflt ->SP_M9N_S 497224.3125 1598028.1250 497063.2813 1598002.7500 496953.1250 1597951.8750 497122.6250 1597985.7500 497190.4375 1597994.2500... (3 Replies)
Discussion started by: ipatah
3 Replies

8. Shell Programming and Scripting

Script to Edit the file content and create new file

I have a requirement, which is as follows *. Folder contains list of xmls. Script has to create new xml files by copying the existing one and renaming it by appending "_pre.xml" at the end. *. Each file has multiple <Name>fileName</Name> entry. The script has to find the first occurance of... (1 Reply)
Discussion started by: sudesh.ach
1 Replies

9. Shell Programming and Scripting

Edit number of lines in a file to single line

Greetings, I have a file: hostnames.txt which has - # cat hostnames.txt machine1 machine2 I need the output to be saved to a variable as: HOSTNAMELIST=machine1,machine2 Please advise. Thanks, Chiru (3 Replies)
Discussion started by: chiru_h
3 Replies

10. Shell Programming and Scripting

Edit a line in a file with perl

Hi, How can I edit a line in a file? For example, a.txt contains: start: 1 2 3 4 stop: a b c d and I want to change "3" to "9" and to add "5" after "4" the result should be (a.txt): start: 1 9 3 4 5 stop: a b c d Thanks, zed (5 Replies)
Discussion started by: zed
5 Replies
Login or Register to Ask a Question