Sponsored Content
Top Forums Shell Programming and Scripting appending data to last line of file Post 302431276 by malcolmpdx on Monday 21st of June 2010 09:52:58 AM
Old 06-21-2010
appending data to last line of file

A friend contacted me recently with an interesting question. We got something worked out, but I'm curious what answers you all can come up with.

Given a shell script (in bash) that processes a bunch of data and appends it to a file, how would you append the date, time, and a filename to the last line of the output?

Example:

output file:

Code:
355.355 234.123. 229.812
355.355 234.153. 229.815
355.335 234.123. 229.812

Desired output
Code:
355.355 234.123. 229.812
355.355 234.153. 229.815
355.335 234.123. 229.812 06/21/10 00:12:43 data.txt

Assume further that this has to happen separately from the part of the script that actually produces the data. It's a function that someone else wrote, and can't be changed. For what it's worth, I first suggested that some sort of time/date/file block be added at the start of the data file. But the requirements above are what my friend wanted, so that's the question.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending data at the first and last line of a file

Hi, Am trying to write a shell script which will append a header and a footer to an existing file. Header will contain details like the current date while the footer will contain the no: of records listed in the file. I know we can use the CAT command, but i have no clue abt the syntax to... (4 Replies)
Discussion started by: brainstormer
4 Replies

2. Shell Programming and Scripting

Appending the line number and a seperator to each line of a file ?

Hi, I am a newb as far as shell scripting and SED goes so bear with me on this one. I want to basically append to each line in a file a delimiter character and the line's line number e.g Change the file from :- aaaaaa bbbbbb cccccc to:- aaaaaa;1 bbbbbb;2 cccccc;3 I have worked... (4 Replies)
Discussion started by: pjcwhite
4 Replies

3. Shell Programming and Scripting

Appending a line in a file after a particular line

Hello, I have got a C file in which I would like to add an include statement of my own. There are already a few include statements and mine should come right after the last existing one (to be neat). With grep I can get the lines containing the word 'include' and I guess I should feed the... (7 Replies)
Discussion started by: maxvirrozeito
7 Replies

4. Shell Programming and Scripting

appending data to file

Hi. I wrote a very simple script and it doesn't work :( It is supposed to go to a certain directory, execute some command and append the output to the file "expo.dat" what it does is that it writes to the file only one entery. I dont know if Im using the write synthax for "append". Here is... (3 Replies)
Discussion started by: Enigma08
3 Replies

5. Shell Programming and Scripting

Appending a column in one file to the corresponding line in a second

It appears that this has been asked and answered in similar fashions previously, but I am still unsure how to approach this. I have two files containing user information: fileA ttim:/home/ttim:Tiny Tim:632 ppinto:/home/ppinto:Pam Pinto:633 fileB ttim:xkfgjkd*&#^jhdfh... (3 Replies)
Discussion started by: suzannef
3 Replies

6. Shell Programming and Scripting

Appending data to the end of a line

I have searched the forms and I can not find info on appending each line of one file to the same line of another file. I know that I can cat one file to another or append the 2nd file to the end of the 1st but not quite sure how to append one line of data to another. For example File 1 has ... (2 Replies)
Discussion started by: scw132
2 Replies

7. UNIX for Dummies Questions & Answers

Appending Date at the end ONLY in first line of file

Hi, My requirement is to append a date in format DDMMYYYYHHMISS at the end of first line of file which is HEADER. I am trying command sed -i '1s/.*/&<date_format>/' <file_name> Where <date_format>=`date +%m%d%Y%H%M%S` I am somehow misisng the right quotes ti get this added in above... (2 Replies)
Discussion started by: sanjaydubey2006
2 Replies

8. Shell Programming and Scripting

Help with data appending to a file

Hi I have a file called text.txt contains x y z when i run a command i will get output like below x 20 z 30 i want to insert x, z value in text.txt file and should be like this x 20 y 0 z 30 can anyone help me please? (1 Reply)
Discussion started by: siva kumar
1 Replies

9. Shell Programming and Scripting

Bash - Appending to specific line in file

I'm working on a personal project, a multiplication quiz script for my kids. In it, the user's performance will be recorded and written to a file. After they've played it a little while, it will start to focus more on the ones that give them the most trouble-- that take a long time to answer or... (4 Replies)
Discussion started by: treesloth
4 Replies

10. UNIX for Beginners Questions & Answers

Delimiter appending in a data file if we receive a less columns than expected

Required No.of field = 12 Let say you got a “~” delimited input file and this file has 6 input fields and now I want to add 12-5=7 number of “~” into this input file in order to make it 12 fields datafile can have n number of records ex., a~b~c~d~12~r a~b~c~d~12~r a~b~c~d~12~r... (19 Replies)
Discussion started by: LJJ
19 Replies
iconv_pc_cyr(5)                                         Standards, Environments, and Macros                                        iconv_pc_cyr(5)

NAME
iconv_pc_cyr - code set conversion tables for Alternative PC Cyrillic DESCRIPTION
The following code set conversions are supported: +---------------------------------------------------------------------+ | Code Set Conversions Supported | +--------------+--------+--------------+--------+---------------------+ | Code |Symbol |Target Code |Symbol | Target Output | +--------------+--------+--------------+--------+---------------------+ |PC Cyrillic |alt |ISO 8859-5 |iso5 | ISO 8859-5 Cyrillic | +--------------+--------+--------------+--------+---------------------+ |PC Cyrillic |alt |KOI8-R |koi8 | KOI8-R | +--------------+--------+--------------+--------+---------------------+ |PC Cyrillic |alt |MS 1251 |win5 | Windows Cyrillic | +--------------+--------+--------------+--------+---------------------+ |PC Cyrillic |alt |Mac Cyrillic |mac | Macintosh Cyrillic | +--------------+--------+--------------+--------+---------------------+ CONVERSIONS
The conversions are performed according to the following tables. All values in the tables are given in octal. PC Cyrillic to ISO 8859-5 For the conversion of PC Cyrillic to ISO 8859-5, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | PC Cyrillic | ISO 8859-5 | PC Cyrillic | ISO 8859-5 | |24 | 4 |231 |311 | |200 | 260 |232 |312 | |201 | 261 |233 |313 | |202 | 262 |234 |314 | |203 | 263 |235 |315 | |204 | 264 |236 |316 | |205 | 265 |237 |317 | |206 | 266 |240 |320 | |207 | 267 |241 |321 | |210 | 270 |242 |322 | |211 | 271 |243 |323 | |212 | 272 |244 |324 | |213 | 273 |245 |325 | |214 | 274 |246 |326 | |215 | 275 |247 |327 | |216 | 276 |250 |330 | |217 | 277 |251 |331 | |220 | 300 |252 |332 | |221 | 301 |253 |333 | |222 | 302 |254 |334 | |223 | 303 |255 |335 | |224 | 304 |256 |336 | |225 | 305 |257 |337 | |226 | 306 |260-337 |255 | |227 | 307 |360 |241 | |230 | 310 |362-376 |255 | +---------------+----------------+----------------+---------------+ PC Cyrillic to KOI8-R For the conversion of PC Cyrillic to KOI8-R, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | PC Cyrillic | KOI8-R | PC Cyrillic | KOI8-R | |24 | 4 |242 |327 | |200 | 341 |243 |307 | |201 | 342 |244 |304 | |202 | 367 |245 |305 | |203 | 347 |246 |326 | |204 | 344 |247 |332 | |205 | 345 |250 |311 | |206 | 366 |251 |312 | |207 | 372 |252 |313 | |210 | 351 |253 |314 | |211 | 352 |254 |315 | |212 | 353 |255 |316 | |213 | 354 |256 |317 | |214 | 355 |257 |320 | |215 | 356 |260-337 |255 | |216 | 357 |340 |322 | |217 | 360 |341 |323 | |220 | 362 |342 |324 | |221 | 363 |343 |325 | |222 | 364 |344 |306 | |223 | 365 |345 |310 | |224 | 346 |346 |303 | |225 | 350 |347 |336 | |226 | 343 |350 |333 | |227 | 376 |351 |335 | |230 | 373 |352 |337 | |231 | 375 |353 |331 | |232 | 377 |354 |330 | |233 | 371 |355 |334 | |234 | 370 |356 |300 | |235 | 374 |357 |321 | |236 | 340 |360 |263 | |237 | 361 |361 |243 | |240 | 301 |362-376 |255 | |241 | 302 | | | +---------------+----------------+----------------+---------------+ PC Cyrillic to MS 1251 For the conversion of PC Cyrillic to MS 1251, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | PC Cyrillic | MS 1251 | PC Cyrillic | MS 1251 | |24 | 4 |242 |342 | |200 | 300 |243 |343 | |201 | 301 |244 |344 | |202 | 302 |245 |345 | |203 | 303 |246 |346 | |204 | 304 |247 |347 | |205 | 305 |250 |350 | |206 | 306 |251 |351 | |207 | 307 |252 |352 | |210 | 310 |253 |353 | |211 | 311 |254 |354 | |212 | 312 |255 |355 | |213 | 313 |256 |356 | |214 | 314 |257 |357 | |215 | 315 |260-337 |210 | |216 | 316 |340 |360 | |217 | 317 |341 |361 | |220 | 320 |342 |362 | |221 | 321 |343 |363 | |222 | 322 |344 |364 | |223 | 323 |345 |365 | |224 | 324 |346 |366 | |225 | 325 |347 |367 | |226 | 326 |350 |370 | |227 | 327 |351 |371 | |230 | 330 |352 |372 | |231 | 331 |353 |373 | |232 | 332 |354 |374 | |233 | 333 |355 |375 | |234 | 334 |356 |376 | |235 | 335 |357 |377 | |236 | 336 |360 |250 | |237 | 337 |361 |270 | |240 | 340 |362-376 |210 | |241 | 341 | | | +---------------+----------------+----------------+---------------+ PC Cyrillic to Mac Cyrillic For the conversion of PC Cyrillic to Mac Cyrillic, all characters not in the following table are mapped unchanged. +-----------------------------------------------------------------+ | | Conversions|Performed | | | PC Cyrillic | Mac Cyrillic | PC Cyrillic | Mac Cyrillic | |24 | 4 |341 |361 | |240 | 340 |342 |362 | |241 | 341 |343 |363 | |242 | 342 |344 |364 | |243 | 343 |345 |365 | |244 | 344 |346 |366 | |245 | 345 |347 |367 | |246 | 346 |350 |370 | |247 | 347 |351 |371 | |250 | 350 |352 |372 | |251 | 351 |353 |373 | |252 | 352 |354 |374 | |253 | 353 |355 |375 | |254 | 354 |356 |376 | |255 | 355 |357 |337 | |256 | 356 |360 |335 | |257 | 357 |361 |336 | |260-337 | 40 |362-376 |40 | |340 | 360 | | | +---------------+----------------+----------------+---------------+ 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_pc_cyr(5)
All times are GMT -4. The time now is 03:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy