Sponsored Content
Full Discussion: Copy pattern inside the file
Top Forums UNIX for Beginners Questions & Answers Copy pattern inside the file Post 303014952 by arunkumar_mca on Saturday 24th of March 2018 07:04:32 AM
Old 03-24-2018
Both gawk didn't worked. I got the below error. I think I am using old version of awk, Below is what I tried my input files in format like LATAM_TRANS so I replace the input file in the command

Code:
gawk -i inplace -v -F";" 'FNR==1{close(file);file=FILENAME} /22001/{val=val?val ORS $0:$0;$1=11048;val_11048=val_11048?val_11048 ORS $0:$0;next} /22002/ && val && val_11048{print val_11048 ORS val;val=val_11048="";next} 1' OFS=";"  LATAM_TRANS

Usage: gawk [POSIX or GNU style options] -f progfile [--] file ...
Usage: gawk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:          GNU long options:
        -f progfile             --file=progfile
        -F fs                   --field-separator=fs
        -v var=val              --assign=var=val
        -m[fr] val
        -W compat               --compat
        -W copyleft             --copyleft
        -W copyright            --copyright
        -W dump-variables[=file]        --dump-variables[=file]
        -W exec=file            --exec=file
        -W gen-po               --gen-po
        -W help                 --help
        -W lint[=fatal]         --lint[=fatal]
        -W lint-old             --lint-old
        -W non-decimal-data     --non-decimal-data
        -W profile[=file]       --profile[=file]
        -W posix                --posix
        -W re-interval          --re-interval
        -W source=program-text  --source=program-text
        -W traditional          --traditional
        -W usage                --usage
        -W version              --version

To report bugs, see node `Bugs' in `gawk.info', which is
section `Reporting Problems and Bugs' in the printed version.

gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.

Examples:
        gawk '{ sum += $1 }; END { print sum }' file
        gawk -F: '{ print $1 }' /etc/passwd




Quote:
Originally Posted by RudiC
How do you know it's 11048 that is missing? And how do you know 22001 should be used to fill in the gap?
If those are constants, and no logics / algorithms needed / applied, it might be easier to just use an editor and do a block copy.
Yes the values are constant. I am using VI to do that. I have to do on 120 files on a directory. Like that I am having 18 directories. I have to find where 22001 is in the file and the copy it and then place it above as 11048. So it is taking time. Worked for 7 hours I completed only 96 files where I have 18*120 files

Last edited by arunkumar_mca; 03-24-2018 at 08:10 AM.. Reason: spelling correction
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to search a pattern inside a zipped file ie (.gz file) with out unzipping it

How to search a pattern inside a zipped file ie (.gz file) with out unzipping it? using grep command.. Bit urgent.. pls..help me (2 Replies)
Discussion started by: senraj01
2 Replies

2. Shell Programming and Scripting

Need help in sed command ( Replacing a pattern inside a file with a variable value )

Hello, The following sed command is giving error sed: -e expression #1, char 13: unknown option to `s' The sed command is echo "//-----" | sed "s/\/\/---*/$parChk/g" where parChk="//---ee-" How can i print the variable value from sed command ? And is it possible to replace a... (2 Replies)
Discussion started by: frozensmilz
2 Replies

3. Shell Programming and Scripting

pattern replace inside text file using sed

Hi, I have a situation where I want to replace some occurrences of ".jsp" into ".html" inside a text file. For Example: If a pattern found like <a href="http://www.mysite.com/mypage.jsp"> it should be retained. But if a pattern found like <a href="../mypage.jsp"> it should be changed to... (4 Replies)
Discussion started by: meharo
4 Replies

4. Shell Programming and Scripting

how to find the pattern inside the file and replace it

hello everybody, I have a group of file eg- sample1 sample2 sample3 sample4 each file contain this :- cat sample1 SEQ_NUM,1,UPESI1 My requirement is to change the value-UPESI1 to UPE10 in file which contain this pattern -UPESI1. any help is appreciated. (2 Replies)
Discussion started by: abhigrkist
2 Replies

5. Homework & Coursework Questions

copy files inside a text file

Hi Guys , I am new to this and Hi to all ,Need your help I am trying to copy Files which are inside file.txt The files inside file.txt are inthe below order file1.log file2.log file3.log ....... I want to copy these files to an output Directory , Please help (1 Reply)
Discussion started by: hc17972
1 Replies

6. Homework & Coursework Questions

copy files inside a text file

Hi Guys , I am new to this and Hi to all ,Need your help I am trying to copy Files which are inside file.txt The files inside file.txt are inthe below order file1.log file2.log file3.log ....... I want to copy these files to an output Directory , Please help (1 Reply)
Discussion started by: hc17972
1 Replies

7. Shell Programming and Scripting

Help with matching pattern inside a file

I have a huge file that has roughly 30304 lines. I need to extract specific info from that file. For example, Box 1 > *aaaaaaaajjjj* > hbbvjvj > jdnnfddllll > *dgdfhfekwjh* Box 2 > *aaaaaaa'aj'jjj* > dse hkjuejef bfdw > dyeee > dsewq > *dgdfhfekwjh* >feweiuei Box 3 > *aaaa"aaaaj"jjj* >... (25 Replies)
Discussion started by: Ernst
25 Replies

8. Shell Programming and Scripting

Finding the pattern and replacing the pattern inside the file

i have little challenge, help me out.i have a file where i have a value declared and and i have to replace the value when called. for example i have the value for abc and ccc. now i have to substitute the value of value abc and ccc in the place of them. Input File: go to &abc=ddd; if... (16 Replies)
Discussion started by: saaisiva
16 Replies

9. Shell Programming and Scripting

Copy and paste text inside a xml file

I have a really big XML file. I need copy the value of one tag inside another one tag. I try to publish one example. <channel update="i" site="merge-xmltv" site_id="" xmltv_id="Rai 1">Rai 1</channel> <channel update="i" site="merge-xmltv" site_id="" xmltv_id="Rai 1 +2HD">Rai 1... (6 Replies)
Discussion started by: Tapiocapioca
6 Replies

10. UNIX for Beginners Questions & Answers

Search a string inside a pattern matched block of a file

How to grep for searching a string within a begin and end pattern of a file. Sent from my Redmi 3S using Tapatalk (8 Replies)
Discussion started by: Baishali
8 Replies
File::Copy::Link(3pm)					User Contributed Perl Documentation				     File::Copy::Link(3pm)

NAME
File::Copy::Link - Perl extension for replacing a link by a copy of the linked file. SYNOPSIS
use File::Copy::Link; copylink 'file.lnk'; use File::Copy::Link qw(safecopylink); safecopylink 'file.lnk'; DESCRIPTION
"copylink" reads the filename linked to by the argument and replaced the link with a copy of the file. It opens a filehandle to read from the link, deletes the link, and then copies the filehandle back to the link. "safecopylink" does the same as "copylink" but without the open-and-delete manouvre. Instead, it uses "File::Spec::Link" to find the target of the link and copies from there. This module is mostly a wrapper round "File::Spec::Link::linked" and "File::Copy::copy", the functionality is available in a command line script copylink. EXPORT Nothing by default, can export "copylink", `"safecopylink". SEE ALSO
copylink(1) File::Copy(3) File::Spec::Link(3) AUTHOR
Robin Barker, <Robin.Barker@npl.co.uk> COPYRIGHT AND LICENSE
Copyright 2003, 2006, 2007 by Robin Barker This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.4 2011-09-30 File::Copy::Link(3pm)
All times are GMT -4. The time now is 04:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy