Sponsored Content
Full Discussion: Replacing nth occurrence
Top Forums Shell Programming and Scripting Replacing nth occurrence Post 302585575 by tarun_agrawal on Wednesday 28th of December 2011 09:46:54 PM
Old 12-28-2011
Code:
echo "abc|def|ghi|jkl|mno|pqr|stu|vwx|yz" | 
awk -vFS=''  '{ 
 for(i=1;i<=NF;i++) 
 {   
   if(j==3)
   { 
       $i=$i"\n";j=0;
   } 
   printf("%s", $i); 
   if($i=="|") 
   {
     j++
   }  
 }  
              }
END{ print "\n"}  '


Last edited by Franklin52; 12-29-2011 at 10:37 AM.. Reason: Please use code tags for data and code samples, thank you
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Finding nth occurrence in line and replacing it

Hi, I have several files with data that have to be imported to a database. These files contain records with separator characters. Some records are corrupt (2 separators are missing) and I need to correct them prior to importing them into the db. Example: ... (5 Replies)
Discussion started by: stresing
5 Replies

2. Shell Programming and Scripting

Replacing a string in nth line

Hello All, How to replace a string in nth line of a file using sed or awk. For Ex: test.txt Line 1 : TEST1 TEST2 TEST3 Line 2 : TEST1 TEST2 TEST3 TEST4 Line 3 : TEST1 TEST2 TEST3 TEST5 Line 4 : TEST1 TEST2 TEST3 TEST6 Line 5 : TEST1 TEST2 TEST3 TEST7 i want to go to 4th line of a... (1 Reply)
Discussion started by: maxmave
1 Replies

3. Shell Programming and Scripting

Replacing nth occurence

Hi My input file is like this for eg: abc abc abc abc abc abc i would like to replace "abc" with "cba" where the occurrence is divisible by 2 of eg here 2nd, 4th and 6th occurence shud be replace can anyone suggest in awk or sed (11 Replies)
Discussion started by: raghav288
11 Replies

4. Shell Programming and Scripting

find string nth occurrence in file and print line number

Hi I have requirement to find nth occurrence in a file and capture data from with in lines (between lines) Data in File. <QUOTE> <SESSION> <ATTRIBUTE NAME='Parameter Filename' VALUE='file1.parm'/> <ATTRIBUTE NAME='Service Name' VALUE='None'/> </SESSION> <SESSION> <ATTRIBUTE... (6 Replies)
Discussion started by: tmalik79
6 Replies

5. Shell Programming and Scripting

How to output all lines following Nth occurrence of string

Greetings experts. Searched the forums (perhaps not hard enough?) - Am searching for a method to capture all output from a log file following the nth occurrence of a known string. Background: Using bash, I want to monitor my Oracle DB alert log file. The script will count the total # of... (2 Replies)
Discussion started by: cjtravis
2 Replies

6. Shell Programming and Scripting

Insert new pattern in newline after the nth occurrence of a line pattern - Bash in Ubuntu 12.04

Hi, I am getting crazy after days on looking at it: Bash in Ubuntu 12.04.1 I want to do this: pattern="system /path1/file1 file1" new_pattern=" data /path2/file2 file2" file to edit: data.db - I need to search in the file data.db for the nth occurrence of pattern - pattern must... (14 Replies)
Discussion started by: Phil3759
14 Replies

7. Shell Programming and Scripting

Extract the text between the nth occurrence of square brackets

Please can someone help with this? I have a file with lines as follows: word1 word2 word3 word4 word5 word6 word7 word8 word1 word2 word3 word4 word5 word6 word7 word8 word1 word2 word3 word4 word5 word6 word7 word8 word1 word2 word3 word4 word5 word6 word7 word8 When I use the... (7 Replies)
Discussion started by: Subhadeep_Sahu
7 Replies

8. Shell Programming and Scripting

How to insert file contents after nth occurrence of a string using sed?

Hi, I would like to know how, using sed, be able to insert contents of file2 in file1 after say the second occurrence of a given string? e.g. > cat file1 banana apple orange apple banana pear tangerine apple > cat file2 I don't like apples What would be the sed command to insert... (5 Replies)
Discussion started by: dimocn
5 Replies

9. Shell Programming and Scripting

Replacing nth field with nth_text for each line in a file

Hi All, I am very new to shell scripting and tried to search this in the forum but no luck. Requirment: I have an input file which is comma separated. I need to replace the value in 4th column with another value. This has to happen for all the lines in the file. Sample data: Input... (2 Replies)
Discussion started by: arunkumarsd
2 Replies

10. Shell Programming and Scripting

Trim after nth occurrence with loop

Hello, Below command trims right after the nth occurrence of a string. When I try in while loop, it is not working. In Terminal IFS=/ ; read -ra val < Textfile ; echo "${val:0:3}" It gives only one line: sunday/monday/tuesday Textfile: sunday/monday/tuesday/wednesday/thursday... (2 Replies)
Discussion started by: baris35
2 Replies
tt_message_abstainer(library call)										tt_message_abstainer(library call)

NAME
tt_message_abstainer -- return offer's nth abstaining procid SYNOPSIS
#include <Tt/tt_c.h> char *tt_message_abstainer( Tt_message m, int n); DESCRIPTION
The tt_message_abstainer function returns the procid of the nth abstainer of the specified message. The m argument is the opaque handle for the message involved in this operation. The n argument is the number of the abstainer to be returned. The first abstainer is numbered zero. RETURN VALUE
Upon successful completion, the tt_message_abstainer function returns the procid of the nth abstainer. The application can use tt_ptr_error to extract one of the following Tt_status values from the returned pointer: TT_OK The operation completed successfully. TT_ERR_PROCID There is no valid default procid, perhaps because tt_open has not yet been called. TT_ERR_NUM The integer value passed was invalid (out of range). TT_ERR_STATE The specified message is not in state TT_RETURNED. Since only TT_OFFERs can be in state TT_RETURNED, this status will be returned if the specified message is a TT_NOTICE or a TT_REQUEST. TT_ERR_POINTER The pointer passed does not point to an object of the correct type for this operation. APPLICATION USAGE
The application can use tt_free to free any data stored in the address returned by the ToolTalk API. SEE ALSO
Tt/tt_c.h - Tttt_c(5), tt_message_abstainers_count(3), tt_ptr_error(3), tt_free(3). tt_message_abstainer(library call)
All times are GMT -4. The time now is 12:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy