Sponsored Content
Full Discussion: Modify text file using awk
Top Forums Shell Programming and Scripting Modify text file using awk Post 302811469 by Don Cragun on Thursday 23rd of May 2013 02:56:05 PM
Old 05-23-2013
Quote:
Originally Posted by mehar
Thanks, i have the similar fix which is doing what i need. Here is the code.

Code:
awk 'BEGIN{OFS="\t"}{n=split ($8,TMP,";"); $8=""; for (i=1; i<=n; i++) if (match (TMP[i], /^DP=|^MQ=|^resource.EFF=/)) {sub (/^.*=/, "" ,TMP[i]); $12=$12 ($12?"\t":"") TMP[i]} {gsub("[\\|()]", "\t")}}1' file

But i have a new problem,

Code:
chr1	    901534	rs21932296	   T	G	34.77	0/1:3,2:5:63:63,0,64	GATKSAM	5	55.21	INTRON	MODIFIER				CTDP1	protein_coding	CODING	ENSCAFT00000000012	11

If we observe after MODIFIER i have a series of empty tabs. When i am piping this input to another awk command to perform s0me other action with the command,
Code:
awk 'BEGIN{OFS="\t"}{split ($7,TMP,":"); $7= TMP[1]}1'

it is replacing multiple empty tabs into a single tab and gives the output like below:

Code:
chr1	    901534	rs21932296	  T	G	34.77	 0/1	GATKSAM	5	55.21	INTRON	MODIFIER	CTDP1	protein_coding	CODING	ENSCAFT00000000012	11


I don't want the multiple tabs to be replaced by single tab. Could you help where im going wrong?
You're just setting the output field separator to tab, you also need to set the input field separator. Change: BEGIN{OFS="\t"} to: BEGIN{FS=OFS="\t"}.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

modify file using awk

I have a file, a.asc which is generated from a shell script: -----BEGIN PGP MESSAGE----- Version: PGP 6.5.8 qANQR1DBwE4DR5PN6zVjZTcQA/9z5Eg94cwYdTnC7v+JUegQuJwHripqnyjFrEs/ejzKYCNmngbHHmf8V4K3uFkYyp74aFf+CdymA030RKs6ewOwkmqRW19oIXCgVe8Qmfg+/2KTq8XN =0QSP -----END PGP MESSAGE----- I want... (12 Replies)
Discussion started by: nattynatty
12 Replies

2. Shell Programming and Scripting

Modify a text or xml file

Hi all, I want to write a shell which would allow me to edit a text file or a xml file. Basically i want to add a new node in a existing xml file. The values for this new node are based on user input. Thanks in advance Zing (9 Replies)
Discussion started by: zing
9 Replies

3. Shell Programming and Scripting

Modify Specific Line of a Text File

Given a text file, how do you add a line of text after a specific line number? I believe I would want to use "sed" but I am unsure of the syntax. Thank you. Mike (5 Replies)
Discussion started by: msb65
5 Replies

4. Shell Programming and Scripting

Need help to modify perl script: Text file with line and more than 1 space

Dear Friends, I am beginner in Perl and trying to find the problem in a script. Kindly help me to modify the script. My script is not giving the output for the last field and followed text (LA: Language English). Input file & script as follows: Input file: Thu Mar 19 2:34:14 EDT 2009 STC... (3 Replies)
Discussion started by: srsahu75
3 Replies

5. UNIX for Dummies Questions & Answers

Modify Text File

Hi, I would like to remove any lines from a text file that begin with #, or that are blank. How can I do that with BASH? Mike (3 Replies)
Discussion started by: msb65
3 Replies

6. Shell Programming and Scripting

Modify text file using shell script

Hi, I have a text file which is following format - COL VAL ABC 1 ABC 2 ABC 3 ABC 4 ABC 5 My requirement is to search for a particular value (provided by user) in the file and comment the previous entries including that as well. E.g. If I search for number 3, then the output... (6 Replies)
Discussion started by: bhupinder08
6 Replies

7. Shell Programming and Scripting

Modify the text file by script

Hi All the Helpers! I have a text file which looks like input.txt.I would request to please suggest me how can I make this file look like output.txt input.txt VOP 111 0 1 2 DEM 111 0 222 333 444 555 879 888 987 888 989 VOP 118 0... (2 Replies)
Discussion started by: Indra2011
2 Replies

8. Shell Programming and Scripting

Modify one line in a plain text file

Hi everyone, I want to know, if there is a way to modify one line in a text file with unix script, with out re-writing all the file. For example, i have this file: CONFIGURATION_1=XXXX CONFIGURATION_2=YYYY CONFIGURATION_3=ZZZZ supose i have a command or function "modify" that... (7 Replies)
Discussion started by: Xedrox
7 Replies

9. Shell Programming and Scripting

Modify text file using sed

Hello all, I have some text files I need to do the following on: Delete banner page (lines 1-56) --I am doing this using sed Remove ^M --I am doing this using vi Remove trailer page --this can vary based on the contents of the file, it usually starts with *************************** I am... (5 Replies)
Discussion started by: jeffs42885
5 Replies

10. UNIX for Beginners Questions & Answers

Modify text file if found multiple pattern match for every line.

Looking for help, i have input file like below and want to modify to expected output, if can without create additional file, hope can direct modify it. have 2 thing need do. 1st is adding a word (testplan generation off) after ! ! IPG: Tue Aug 07 14:31:17 2018 2nd is adding... (16 Replies)
Discussion started by: kttan
16 Replies
ns_adp_exception(3aolserver)				    AOLserver Built-In Commands 			      ns_adp_exception(3aolserver)

__________________________________________________________________________________________________________________________________________________

NAME
ns_adp_abort, ns_adp_break, ns_adp_exception, ns_adp_return - ADP exception handling SYNOPSIS
ns_adp_abort ?result? ns_adp_break ?result? ns_adp_exception ?varName? ns_adp_return ?result? _________________________________________________________________ DESCRIPTION
These commands enable early return and interrupt of an ADP execution. Internally, the exception routines sets a flag and return TCL_ERROR to begin unwinding the current Tcl call stack and return control to the ADP evaluation engine. It is possible for an enclosing catch com- mand to catch the exception and stop Tcl from returning control to ADP. The ns_adp_exception command can be used to test for this condi- tion. ns_adp_abort ?result? This command stops ADP processing, raising an execution and unwinding the stack to the top level as an error condition. The request handling code which invokes the first ADP file will normallly generate an error message in this case, ignoring the contents of the output buffer, if any. Note that the exeception can be caught by a catch command in script block which executes ns_adp_abort. How- ever, when that block returns control to the ADP execution engine, the stack will be continue to be unwound. The optional result argument, if present, will be used to set the Tcl interpreter result string. ns_adp_break ?result? This command stops execution of ADP and unwinds the ADP call stack. Unlike ns_adp_abort, the request handling code will generate a normal HTTP response with any contents of the output buffer. The optional result argument, if present, will be used to set the Tcl interpreter result string. ns_adp_exception ?varName? This command returns a boolean value if an exception has been raised. The optional varName provides the name of a variable to store one of ok, break, abort, or return to indicate the type of exception raised. ns_adp_return ?result? This function halts processing of the current ADP and sends any pending output (from ns_adp_puts or static HTML) up to the point where it was called to the browser. Nothing in the current ADP is output or executed after it is called. The return_value, if spec- ified, becomes the return value of the ADP. Note that this function returns only one level up the call stack. By contrast, ns_adp_abort and ns_adp_break will return all the way up the call stack. ns_adp_return is typically used from an ADP included by another ADP, to stop processing of the inner ADP while allowing the calling ADP to continue. The optional result argument, if present, will be used to set the Tcl interpreter result string. EXAMPLE
The following example demonstrates halting execution of the ADP after returning a complete response with one of the ns_return style com- mands: <% if !$authorized { ns_returnunauthorized; # Send complete response. ns_adp_abort; # Execution stops here. } %>. SEE ALSO
ns_adp(n) KEYWORDS
ADP, dynamic pages, exception AOLserver 4.5 ns_adp_exception(3aolserver)
All times are GMT -4. The time now is 09:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy