Sponsored Content
Top Forums Shell Programming and Scripting Place variables at the beginning of each line Post 302471889 by GoldenFire on Monday 15th of November 2010 01:29:20 PM
Old 11-15-2010
Place variables at the beginning of each line

Hello all,

I am very new to the shell scripting and I hope someone can help me with this.
I have thousands of files with certain format of information and I need to do this for all my files.

For each file, grab the numbers in the first and second rows and place them in the position 1 and 2 of the rest rows.
The numbers of the first and second rows are different for each file and also each file has different number of rows.

Here's the examples:

Code:
ptrfghbc 44.23
mkhtwsbhp 234.51
1995 56 26 26358 266665 251 32
1995 65 58 22355 551223 352 25
1996 32 52 55852 255632 335 25

I'd like to have something like this:

Code:
ptrfghbc 44.23
mkhtwsbhp 234.51
44.23 234.51 1995 56 26 26358 266665 251 32
44.23 234.51 1995 65 58 22355 551223 352 25
44.23 234.51 1996 32 52 55852 255632 335 25

Your help is much appreciated.
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 11-15-2010 at 06:01 PM.. Reason: code tags, please!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unix Script with line number at beginning of each line.

Could anybody help me. I need to create a script that reads a text file from STDIN and prints out the file to STDOUT with line numbers at the beginning of each line. Thanks. (5 Replies)
Discussion started by: mascorro
5 Replies

2. Shell Programming and Scripting

Getting the value of a line, that changes place

Hi I am trying to get the value of several results in a file called seq032.diag. The values I am looking for is down under Smooth Tracking nodes and is for g01r01 g02r01 s01t02 etc etc. The problem is that when I try to use look for text and tail etc, it works fine in one result file. In... (1 Reply)
Discussion started by: Navigatorchief
1 Replies

3. Shell Programming and Scripting

SED command help: Can we pass predefined variables in place of regex

Hi All, I have a doubt. Can we assign a regular expression for pattern searching to a variable in a script and then use that variable in place of a regular expression in sed command.I tried but got some syntax error!!Is it not possible.Because my requirement is that i have a generic script to get... (8 Replies)
Discussion started by: usha rao
8 Replies

4. Shell Programming and Scripting

Using NR with two variables at the beginning of awk

hi My requirement is this: I have a file having around 100000 records pipe delimited. Now I want to compare record 1 with record 2 and similarly record3 with record 4, this goes on.. For this purpose i put a script as follows: #!bin/ksh ct_line=1 nxt_line=`expr ${ct_line} + 1` awk -F "|"... (1 Reply)
Discussion started by: ramkrix
1 Replies

5. Shell Programming and Scripting

Space at beginning of the line

How can I delete spaces at the begining of all lines of my file ? (2 Replies)
Discussion started by: Sara_84
2 Replies

6. UNIX for Dummies Questions & Answers

How to specify beginning-of-line/end-of-line characters inside a regex range

How can I specify special meaning characters like ^ or $ inside a regex range. e.g Suppose I want to search for a string that either starts with '|' character or begins with start-of-line character. I tried the following but it does not work: sed 's/\(\)/<do something here>/g' file1 ... (3 Replies)
Discussion started by: jawsnnn
3 Replies

7. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

8. Shell Programming and Scripting

comment a line of the patterns is a the beginning of the line

I need to comment the lines starting with pattern "exclude" or "exclude=". If the work exclude comes at any other part, ignore it. Also, ignore, excludes, excluded etc. Ie only comment the line starting with exclude. File contents. exclude exclude= hi I am excluded excludes excludes= ... (9 Replies)
Discussion started by: anil510
9 Replies

9. Shell Programming and Scripting

beginning less from line #

Hi from a script i want to to read a file beginning at line e.g. number 21 to the EOF. less +n21 temp.txt Bevor the result, it brings an empty page, so that i cant use for scripting. Any idea how the problem can be solved? Thanks in advance! IMPe (2 Replies)
Discussion started by: IMPe
2 Replies

10. Red Hat

Remove new line for a particular place

Hello All, I have a text file which gets uploaded to tables using shells script. However before running that script I need to alter it, like in the below I have to firstly find the word 1234 and remove the new line from end of it. 1234,5678,fasfasasfsadf abc changes to... (11 Replies)
Discussion started by: Sandeep_sandy
11 Replies
UNSHAR(1)						      General Commands Manual							 UNSHAR(1)

NAME
unshar - unpack a shar file SYNOPSIS
unshar [ options ] [ file ... ] DESCRIPTION
Unshar scans mail messages looking for the start of a shell archive. It then passes the archive through a copy of the shell to unpack it. It will accept multiple files. If no files are given, standard input is used. OPTIONS
Options have a one letter version starting with - or a long version starting with --. The exception is --help and --version, which does not have a short version. --version Print the version number of the program on standard output, then immediately exits. --help Print a help summary on standard output, then immediately exits. -d DIRECTORY --directory=DIRECTORY Change directory to DIRECTORY before unpacking any files. -c --overwrite Passed as an option to the shar file. Many shell archive scripts (including those produced by `shar' 3.40 and newer) accepts a -c argument to indicate that existing files should be overwritten. -e --exit-0 This option exists mainly for people who collect many shell archives into a single mail folder. With this option, `unshar' isolates each different shell archive from the others which have been put in the same file, unpacking each in turn, from the beginning of the file towards its end. Its proper operation relies on the fact that many shar files are terminated by a `exit 0' at the beginning of a line. Option -e is internally equivalent to -E "exit 0". -E STRING --split-at=STRING This option works like -e, but it allows you to specify the string that separates archives if `exit 0' isn't appropriate. For example, noticing that most `.signatures' have a `--' on a line right before them, one can sometimes use `--split-at=--' for splitting shell archives which lack the `exit 0' line at end. The signature will then be skipped altogether with the headers of the following message. -f --force The same as -c. SEE ALSO
shar(1) DIAGNOSTICS
Any message from the shell may be displayed. AUTHORS
The shar and unshar programs is the collective work of many authors. Many people contributed by reporting problems, suggesting various improvements or submitting actual code. A list of these people is in the THANKS file in the sharutils distribution. REPORTING BUGS
Report bugs to <bug-gnu-utils@gnu.org>. Please put sharutils in the subject line. It helps to spot the message. September 10, 1995 UNSHAR(1)
All times are GMT -4. The time now is 05:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy