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
iconv_852(5)						Standards, Environments, and Macros					      iconv_852(5)

NAME
iconv_852 - code set conversion tables for MS 852 (MS-DOS Latin 2) DESCRIPTION
The following code set conversions are supported: +--------------------------------------------------------------------+ | Code Set Conversions Supported | +--------------+--------+--------------+--------+--------------------+ | Code |Symbol |Target Code |Symbol | Target Output | +--------------+--------+--------------+--------+--------------------+ |MS 852 |dos2 |ISO 8859-2 |iso2 | ISO Latin 2 | +--------------+--------+--------------+--------+--------------------+ |MS 852 |dos2 |MS 1250 |win2 | Windows Latin 2 | +--------------+--------+--------------+--------+--------------------+ |MS 852 |dos2 |Mazovia |maz | Mazovia | +--------------+--------+--------------+--------+--------------------+ |MS 852 |dos2 |DHN |dhn | Dom Handlowy Nauki | +--------------+--------+--------------+--------+--------------------+ CONVERSIONS
The conversions are performed according to the following tables. All values in the tables are given in octal. MS 852 to ISO 8859-2 For the conversion of MS 852 to ISO 8859-2, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | MS 852 | ISO 8859-2 | MS 852 | ISO 8859-2 | |24-177 | 40 |271-274 |40 | |200 | 307 |275 |257 | |201 | 374 |276 |277 | |202 | 351 |277-305 |40 | |203 | 342 |306 |303 | |204 | 344 |307 |343 | |205 | 371 |310-316 |40 | |206 | 346 |317 |244 | |207 | 347 |320 |360 | |210 | 263 |321 |320 | |211 | 353 |322 |317 | |212 | 325 |323 |313 | |213 | 365 |324 |357 | |214 | 356 |325 |322 | |215 | 254 |326 |315 | |216 | 304 |327 |316 | |217 | 306 |330 |354 | |220 | 311 |331-334 |40 | |221 | 305 |335 |336 | |222 | 345 |336 |331 | |223 | 364 |337 |40 | |224 | 366 |340 |323 | |225 | 245 |341 |337 | |226 | 265 |342 |324 | |227 | 246 |343 |321 | |230 | 266 |344 |361 | |231 | 326 |345 |362 | |232 | 334 |346 |251 | |233 | 253 |347 |271 | |234 | 273 |350 |300 | |235 | 243 |351 |332 | |236 | 327 |352 |340 | |237 | 350 |353 |333 | |240 | 341 |354 |375 | |241 | 355 |355 |335 | |242 | 363 |356 |376 | |243 | 372 |357 |264 | |244 | 241 |360 |255 | |245 | 261 |361 |275 | |246 | 256 |362 |262 | |247 | 276 |363 |267 | |250 | 312 |364 |242 | |251 | 352 |365 |247 | |252 | 40 |366 |367 | |253 | 274 |367 |270 | |254 | 310 |370 |260 | |255 | 272 |371 |250 | |256-264 | 40 |372 |377 | |265 | 301 |374 |330 | |266 | 302 |375 |370 | |267 | 314 |376 |40 | |270 | 252 | | | +---------------+----------------+----------------+---------------+ MS 852 to MS 1250 For the conversion of MS 852 to MS 1250, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | MS 852 | MS 1250 | MS 852 | MS 1250 | |200 | 307 |270 |252 | |201 | 374 |271-274 |40 | |202 | 351 |275 |257 | |203 | 342 |276 |277 | |204 | 344 |277-305 |40 | |205 | 371 |306 |303 | |206 | 346 |307 |343 | |207 | 347 |310-316 |40 | |210 | 263 |317 |244 | |211 | 353 |320 |360 | |212 | 325 |321 |320 | |213 | 365 |322 |317 | |214 | 356 |323 |313 | |215 | 217 |324 |357 | |216 | 304 |325 |322 | |217 | 306 |326 |315 | |220 | 311 |327 |316 | |221 | 305 |330 |354 | |222 | 345 |331-334 |40 | |223 | 364 |335 |336 | |224 | 366 |336 |331 | |225 | 274 |337 |40 | |226 | 276 |340 |323 | |227 | 214 |341 |337 | |230 | 234 |342 |324 | |231 | 326 |343 |321 | |232 | 334 |344 |361 | |233 | 215 |345 |362 | |234 | 235 |346 |212 | |235 | 243 |347 |232 | |236 | 327 |350 |300 | |237 | 350 |351 |332 | |240 | 341 |352 |340 | |241 | 355 |353 |333 | |242 | 363 |354 |375 | |243 | 372 |355 |335 | |244 | 245 |356 |376 | |245 | 271 |357 |264 | |246 | 216 |360 |255 | |247 | 236 |361 |275 | |250 | 312 |362 |262 | |251 | 352 |363 |241 | |252 | 254 |364 |242 | |253 | 237 |365 |247 | |254 | 310 |366 |367 | |255 | 272 |367 |270 | |256 | 253 |370 |260 | |257 | 273 |371 |250 | |260-264 | 40 |372 |377 | |265 | 301 |374 |330 | |266 | 302 |375 |370 | |267 | 314 |376 |40 | +---------------+----------------+----------------+---------------+ MS 852 to Mazovia For the conversion of MS 852 to Mazovia, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | MS 852 | Mazovia | MS 852 | Mazovia | |205 | 40 |246-247 |40 | |206 | 215 |250 |220 | |210 | 222 |251 |221 | |212-213 | 40 |253 |246 | |215 | 240 |254-270 |40 | |217 | 225 |275 |241 | |220-226 | 40 |276 |247 | |227 | 230 |306-336 |40 | |230 | 236 |340 |243 | |233-234 | 40 |342 |40 | |235 | 234 |343 |245 | |236-243 | 40 |344 |244 | |244 | 217 |345-375 |40 | |245 | 206 | | | +---------------+----------------+----------------+---------------+ MS 852 to DHN For the conversion of MS 852 to DHN, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | MS 852 | DHN | MS 852 | DHN | |200-205 | 40 |244 |200 | |206 | 212 |245 |211 | |207 | 40 |246-247 |40 | |210 | 214 |250 |202 | |211-214 | 40 |251 |213 | |215 | 207 |253 |220 | |216 | 40 |254-270 |40 | |217 | 201 |275 |210 | |220-226 | 40 |276 |221 | |227 | 206 |306-336 |40 | |230 | 217 |340 |205 | |233-234 | 40 |342 |40 | |235 | 203 |343 |204 | |236-237 | 40 |344 |215 | |242 | 216 |345-375 |40 | |252 | 254 | | | +---------------+----------------+----------------+---------------+ FILES
/usr/lib/iconv/*.so conversion modules /usr/lib/iconv/*.t conversion tables /usr/lib/iconv/iconv_data list of conversions supported by conversion tables SEE ALSO
iconv(1), iconv(3C), iconv(5) SunOS 5.10 18 Apr 1997 iconv_852(5)
All times are GMT -4. The time now is 04:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy