Sponsored Content
Top Forums Shell Programming and Scripting Need to replace the first word of a line if it occurs again in the next line(shell) Post 302325922 by quirkasaurus on Tuesday 16th of June 2009 01:13:38 PM
Old 06-16-2009
Code:
 
previous_word=
cat your_file |
while read word rest_of_line ; do
  print_word=$word
  if [ "$print_word" = "$previous_word" ]; then
    print_word="\t"
  fi
  print "$print_word $rest_of_line"
  previous_word=$word
done

 

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

How to replace a word at a parcitular line

Could someone tell me how to replace a word at a particular line by a single SED or AWK command? e.g. I have a file with the contents below: $ cat file1 111 AAA 333 CCC 222 BBB 444 CCC I want to replace the word "CCC" with a blank to get the desired output below: 111 AAA 333 CCC... (3 Replies)
Discussion started by: stevefox
3 Replies

3. Shell Programming and Scripting

Replace only if the keyword is the first word in every line

How do I replace only if the keyword is at the begining of a line? Code: -- a = “This is a print statement” print a -- What if I want to replace print by #print only in the second line i.e only if the line starts with that keyword. Please help me out. I'm new to SED. -----Post... (5 Replies)
Discussion started by: alexzubin
5 Replies

4. Shell Programming and Scripting

Looking for a single line to count how many times one character occurs in a word...

I've been looking on the internet, and haven't found anything simple enough to use in my code. All I want to do is count how many times "-" occurs in a string of characters (as a package name). It seems it should be very simple, and shouldn't require more than one line to accomplish. And this is... (2 Replies)
Discussion started by: Shingoshi
2 Replies

5. 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

6. Shell Programming and Scripting

perl: replace multiple word on a line

Hi All, If I have a line as following: ( MA "vertical" ) How can I convert it to as below: ( BC "horizontal" ) Thanks, --Michael (6 Replies)
Discussion started by: mxn731
6 Replies

7. Shell Programming and Scripting

sed command to replace a word with new line and /

Hi, I have been trying to replace the key word "SQL> spool off " with "/ show errors" with out double quotes in all the files in a directory. above show erros should be displayed next line Could you please help me how to do that. I have tried something like this... (3 Replies)
Discussion started by: pointers
3 Replies

8. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

9. Shell Programming and Scripting

Find word in a line and output in which line the word occurs / no. of times it occurred

I have a file: file.txt, which contains the following data in it. This is a file, my name is Karl, what is this process, karl is karl junior, file is a test file, file's name is file.txt My name is not Karl, my name is Karl Joey What is your name? Do you know your name and... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

10. UNIX for Beginners Questions & Answers

Replace only First Word in Line

I have query to replace the first word in line using below code but its replace the middle word too sed -i 's/load /# LOAD/' /tmp/check.sql Query 1 : UPDATE accheadcon_data_last_upload SET last_upload_date = '2017-07-23' Replace to UPDATE accheadcon_data_last_up# LOAD SET... (1 Reply)
Discussion started by: kaushik02018
1 Replies
vlatai(1L)																vlatai(1L)

NAME
vlatai - Lojban word analyzer SYNOPSIS
vlatai [ -v ] [ word ] DESCRIPTION
vlatai is a program that reads a list of Lojban words from standard input, one word per line. In its usual mode, it writes a single output line for each input line, advising of which kind of Lojban word the input line is. If the input word has cmavo prefixed onto it, vlatai shows the individual cmavo and the base word itself. In the verbose mode (obtained using -v), the workings of the internal state machines used for scanning the word are exposed. This may give some insight into where an error lies on words that can't be parsed, especially if the output is used in conjuction with the report files built during the compilation process. Note that vlatai is primarily a testbench for the word categorizer/splitter inside jbofihe. vlatai is not fully supported or documented as a stand-alone program. OPTIONS
-v Verbose; show lots of information about the evolution of the internal state word The word to check. If no 'word' argument is supplied, the program reads words from standard input, one word per line (with no whitespace around it.) REFERENCES
http://go.to/jbofihe Home page for the jbofihe project (of which cmafihe is part) http://www.lojban.org/ Home page of the Lojban community http://www.rrbcurnow.freeuk.com/lojban/ My Lojban page. AUTHOR
Richard Curnow <rpc@myself.com> December 2000 vlatai(1L)
All times are GMT -4. The time now is 04:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy