Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Script to add text before the first word on a line in a textfile. Post 302509543 by kurumi on Thursday 31st of March 2011 03:53:15 AM
Old 03-31-2011
if you want to prepend word to line, there is no need to do substitution (expensive operation). Just "print" the word before the line
Code:
$ ruby -ne 'print "word #{$_}"' file

applies to other tools/language as well.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies

2. Shell Programming and Scripting

Script to add a single line to middle of text file.

I've got a configuration file that is filled with xml text statements for example: <...../> <...../> <...../> <data id="java-options" value="-server -Djava.security.policy..../> <...../> <...../> <...../> I want to write a korn shell script that will go to this specific line and add a... (2 Replies)
Discussion started by: progkcp
2 Replies

3. Shell Programming and Scripting

How to cut first line only from a text near a specific column without cutting a word

First I have to say thank you to this community and this forum. You helped me very much builing several useful scripts. Now, I can't get a solution the following problem, I'm stuck somehow. Maybe someone has an idea. In short, I dump a site via lynx and pipe the output in a file. I need to... (7 Replies)
Discussion started by: lowmaster
7 Replies

4. Shell Programming and Scripting

Help need to cut the first word of a line in text file

Hi All, I would like help with a script which can get rid of the first work of all lines in text file. File 1 The name is Scott. Output : name is Scott ---------- Post updated at 02:38 PM ---------- Previous update was at 02:37 PM ---------- Hi ALL There is typo error in... (3 Replies)
Discussion started by: bubbly
3 Replies

5. Shell Programming and Scripting

How to find and print the last word of each line from a text file

Can any one help us in finding the the last word of each line from a text file and print it. eg: 1st --> aaa bbbb cccc dddd eeee ffff ee 2nd --> aab ered er fdf ere ww ww f the o/p should be a below. ee f (1 Reply)
Discussion started by: naveen_sangam
1 Replies

6. Shell Programming and Scripting

get the fifth line of a text file into a shell script and trim the line to extract a WORD

FOLKS , i have a text file that is generated automatically of an another korn shell script, i want to bring in the fifth line of the text file in to my korn shell script and look for a particular word in the line . Can you all share some thoughts on this one. thanks... Venu (3 Replies)
Discussion started by: venu
3 Replies

7. Shell Programming and Scripting

from one word for line to plain text

Hello! I've got a very big file (from tokenization) which has one word for line. How is it possible then to rebuild the "original" text, knowing that <s> and </s> are the sentence-delimiters? My file looks like this: <s> && tanzania na Afrika kwa ujumla ambiwa na taifa kubwa... (6 Replies)
Discussion started by: mjomba
6 Replies

8. Shell Programming and Scripting

add a word every other line

hey guys, How to add a line to every other line, means adding a line to the above of all the lines of a file? tnx (4 Replies)
Discussion started by: Johanni
4 Replies

9. Shell Programming and Scripting

Add a word to Text file

Hello, I have a mysql text file. I want add word to it. Thanks for help. Sample sql file: ,'address','166 Warren Street, NY 12534'),(45215,26556,'phone','(518)811-4145'),(151426,15565,'listing_duration','address','122 Hom Street, NY... (6 Replies)
Discussion started by: hoo
6 Replies

10. UNIX for Dummies Questions & Answers

Add a word to Text file

Hello, I have a mysql text file. I want add a word to it. Thanks for help. Sample text: ,'address','166 Warren Street, NY 12534'),(45215,26556,'phone','(518)811-4145'),(151426,15565,'listing_duration' ,'address','233 Tan Street, CA... (1 Reply)
Discussion started by: hoo
1 Replies
trbsd(1)						      General Commands Manual							  trbsd(1)

NAME
trbsd - Translates characters SYNOPSIS
trbsd [-Acs] string1 string2 trbsd -d [-Ac] string1 The trbsd command copies characters from the standard input to the standard output with substitution or deletion of selected characters. OPTIONS
Translates on a byte-by-byte basis. When you specify this option, trbsd does not support extended characters. Complements (inverts) the set of characters in string1 with respect to the universe of characters whose codes are 001 through 377 octal if you specify -A, and all characters if you do not specify -A. Deletes all characters in string1 from output. Changes characters that are repeated output charac- ters in string2 into single characters. DESCRIPTION
Input characters from string1 are replaced with the corresponding characters in string2. The trbsd command cannot handle an ASCII NUL (00) in string1 or string2; it always deletes NUL from the input. The tr command is a System V compatible version of trbsd. Abbreviations such as a-z, standing for a string of characters whose ASCII codes run from character a to character z, inclusive, can be used to introduce ranges of characters. Note that brackets are not special characters. Use the escape character (backslash) to remove the special meaning from any character in a string. Use the followed by 1, 2, or 3 octal digits for the code of a character. If a given character appears more than once in string1, the character in string2 corresponding to its last appearance in string1 will be used in the translation. EXAMPLES
To translate braces into parentheses, enter: trbsd '{}' '()' <textfile >newfile This translates each { (left brace) to a ( (left parenthesis) and each } (right brace) to a ) (right parenthesis). All other char- acters remain unchanged. To translate lowercase ASCII characters to uppercase, enter: trbsd a-z A-Z <textfile >newfile The two strings can be of different lengths: trbsd 0-9 # <textfile >newfile This translates each digit to a # (number sign); if string2 is too short, it is padded to the length of string1 by duplicating its last character. To translate each string of digits to a single # (number sign), enter: trbsd -s 0-9 # <textfile >newfile To trans- late all ASCII characters that are not specified, enter: trbsd -c ' -~' 'A-_' <textfile >newfile This translates each nonprinting ASCII character to the corresponding control key letter (01 translates to A, 02 to B, and so on). ASCII DEL (177), the character that follows ~ (tilde), translates to a ? (question mark). SEE ALSO
Commands: ed(1), sh(1), tr(1) Files: ascii(5) trbsd(1)
All times are GMT -4. The time now is 10:45 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy