Sponsored Content
Top Forums Shell Programming and Scripting Insert a variable to a text file after fixed number of lines Post 302585674 by itkamaraj on Thursday 29th of December 2011 04:22:46 AM
Old 12-29-2011
Code:
 
var="ABCD"
#To insert the ABCD after the 3rd line
nawk -v a="$var" '{if(NR==3){print $0;print a}else{print}}' input.txt

---------- Post updated at 02:52 PM ---------- Previous update was at 02:52 PM ----------

Code:
 
bash-3.00$ var="To Insert"
bash-3.00$ cat test.txt
a
b
c
d
e
f
g
bash-3.00$ nawk -v a="$var" '{if(NR==3){print $0;print a}else{print}}' test.txt
a
b
c
To Insert
d
e
f
g

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to make a number in a text file a variable?

OK this one sounds like it should be a natural... it must be possible to send a number say 200 to a text file and later use it as a variable? yada yada > file.txt how would I retrieve that number to use as a variable? Is this possible? (5 Replies)
Discussion started by: nortypig
5 Replies

2. Shell Programming and Scripting

how to insert text between lines of an existing file using perl

Hi , I need some inputs on how to open a file (file.txt) and parse the text example aaa of the file and bbb of the file and add the text zzzz once i parse (aaa and bbb) and followed by the remaining of the text as it is in the file using perl programming. Thanks in advance (3 Replies)
Discussion started by: madhul2002
3 Replies

3. Shell Programming and Scripting

Insert text into file depending on variable

Hey guys , i have a variable with the contents ... NUMBER=4 and a test file with the contents 1248 1213 1214 1278 1200 3045 3444 2130 I want to execute a script that will produce the following output ( based on NUMBER=4) to be ... create 1248 (1 Reply)
Discussion started by: theshams
1 Replies

4. Shell Programming and Scripting

Number lines of file and assign variable to each number

I have a file with a list of config files numbered on the lefthand side 1-300. I need to have bash read each lines number and assign it to a variable so it can be chosen by the user called by the script later. Ex. 1 some data 2 something else 3 more stuff which number do you... (1 Reply)
Discussion started by: glev2005
1 Replies

5. Shell Programming and Scripting

splitting a huge line of file into multiple lines with fixed number of columns

Hi, I have a huge file with a single line. But I want to break that line into lines of with each line having five columns. My file is like this: code: "hi","there","how","are","you?","It","was","great","working","with","you.","hope","to","work","you." I want it like this: code:... (1 Reply)
Discussion started by: rajsharma
1 Replies

6. Shell Programming and Scripting

how to Insert values in multiple lines(records) within a pipe delimited text file in specific cols

this is Korn shell unix. The scenario is I have a pipe delimited text file which needs to be customized. say for example,I have a pipe delimited text file with 15 columns(| delimited) and 200 rows. currently the 11th and 12th column has null values for all the records(there are other null columns... (4 Replies)
Discussion started by: vasan2815
4 Replies

7. Shell Programming and Scripting

Count number of free lines in a text file

Hi Everybody I want to write a script to count the number of lines in a file that don't ahve any thing on it, the free lines, i try to do it with fgrep "" which means to grep on the spaces but it does not work. help me please? (3 Replies)
Discussion started by: hard_revenge
3 Replies

8. Shell Programming and Scripting

Assign a variable to number of lines in a file

Hello Gurus, Here is my requirement. I need to find the number of lines in a file and need to assign it to a variable. This is what I did and not wroking. #!/bin/ksh set -xv Src_Path=/mac/dev/Generic/SrcFiles Src_Count=wc -l ${Src_Path}/FILE_JUNE.txt Count_file = $Src_Count | awk -F... (2 Replies)
Discussion started by: thummi9090
2 Replies

9. Shell Programming and Scripting

Extracting fixed length number from a text file

Hi, I have a text file with sample records as CASE ID: 20170218881083 Original presentment record for ARN not found for Re-presentment I want to extract the 23 digit number from this file. I thought of using grep but initially couldn't extract the required number. However, after... (16 Replies)
Discussion started by: dsid
16 Replies

10. UNIX for Beginners Questions & Answers

Insert the line number from text file to filename output

Hi everyone :) I have a file "words.txt" containing hundreds of lines of text. Each line contains a slogan. Using the code below i am able to generate an image with the slogan text from each line. The image filename is saved matching the last word on each line. Example: Line 1: We do... (2 Replies)
Discussion started by: martinsmith
2 Replies
XROOTCONSOLE(1) 					    BSD General Commands Manual 					   XROOTCONSOLE(1)

NAME
xrootconsole -- display a file (or stdin) to a transparent window SYNOPSIS
xrootconsole [options] [file] DESCRIPTION
xrootconsole is a small utility which displays its input in a transparent text box on X's root window. It will read from any file listed on the command line or, by default, from stdin. It is most useful when it reads from a FIFO; this allows you to redirect multiple commands to the FIFO and monitor their output. The options are as follows: -fg color This option specifies the color to use for displaying text. The default is ``black.'' -bg color This option specifies the color to AND with the root window, for shaded transparency. The default is ``clear.'' -bw number This option specifies the width of the border around xrootconsole in pixels. The default is 0. -bd color This option specifies the color to use for the border of the window. The default is ``black.'' -fn font This option specifies the font to use for displaying text. The default is ``fixed.'' -c number This option produces output that is number columns wide. Text is written vertically down each column in the order in which text is received from the input file. The default is 1. --topdown Forces xrootconsole to display new lines from its input at the top of the screen, scrolling previous lines down. Default behav- ior is to insert new lines at the bottom and scroll the previous lines up. --wrap Rather than truncating long lines, this option specifies that xrootconsole should wrap excess text to the following line or lines, as necessary. --ansi-color Enable color support by parsing ANSI escape sequences. -geometry geometry This option specifies the preferred size and position of the window; see X(1). The default is ``80x10+0+0.'' -h, --help Displays a detailed usage message and exits. -v, --version Displays the program version and exits. file Optionally specifies a file from which to read input; by default, xrootconsole reads from the standard input. DIAGNOSTICS
Exit status is 0 on success, and 1 if the command fails for any reason. AUTHORS
Eric Youngblut is the original author of xrootconsole. Bob Galloway <bob@de-fac.to> is the current maintainer. Alexandre Duret-Lutz elimi- nated flicker by storing the background pixmap and drawing off-screen. This manual page was written by Zak Johnson <zakj@i.am>. BSD
May 19, 2000 BSD
All times are GMT -4. The time now is 05:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy