Sponsored Content
Full Discussion: cut and paste
Top Forums Shell Programming and Scripting cut and paste Post 302359116 by jp2542a on Monday 5th of October 2009 10:04:59 PM
Old 10-05-2009
Copy this to a text file (strip.awk)

Code:
# strip lines out of file and make new file of lines removed and modified

# set up patterns - any regex will work

BEGIN {
        MY_PAT="835100000000000638"
        NEW_PAT="835100000000000639"
}

# This clause is executed on the opening of each file on the command line
# It first checks to see if this is not the first file and cleans up the
#  previous files and copies the new stripped file to the old file
#  NOTE:  I would prefer if it didn't overwrite the input file...
# It then creates the names and commands it will need later
(FNR == 1) {                    # check if first line of new file
        if ( NR != 1)           # see if this is not first file
        {
                close(FILEOUT)  # if true, then we close previous files
                close(FILELOG)
                system(FILECP)  # do the copy
                system(FILERM)  # remove the work file
        }

        FILEOUT = FILENAME ".strip"     # create striped file name using input file name
        FILELOG = FILENAME ".new"               # create new file

        FILECP = "cp " FILEOUT " " FILENAME     # copy command
        FILERM = "rm " FILEOUT          # remove strip file
}

# This clause executes for every line
# It copies lines from the input file to the appropriate output file
{
        if (  sub(MY_PAT,NEW_PAT) == 0 )      # test for pattern in line
                print > FILEOUT # save to stripped file if pattern not found
        else
                print > FILELOG # save to remove log if pattern match
}

# This clause is executed when the last line of the last file is reached
END {
        system(FILECP)  # clean up last file
        system(FILERM)
}

Then execute:

Code:
awk -f strip.awk <data.file>


It will create a file with .new with the removed lines....
 

10 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

Cut, Copy and Paste with X

One of the things that I have learned to take for granted in the Win32 world is the cut, copy and paste hotkeys of ^X, ^C and ^V. I use these keys all the time under Win32 to copy and paste information from one GUI into another GUI. My question is, does X have a similiar standard? ... (4 Replies)
Discussion started by: auswipe
4 Replies

2. Shell Programming and Scripting

cut & paste

hi i am new to shell scripting, i have been trying to cut columns numbered 1,4 of a file consisiting of 4 columns. Each column is seperated by 2 spaces. for example: john 6102097199 tennessee usa michel 6734590899 texas USA now, i need to cut the name... (3 Replies)
Discussion started by: t_harsha18
3 Replies

3. Shell Programming and Scripting

Cut Paste and Insert Help

Hello I have a very large file where say each line is made up of 80 characters. I want to cut the characters from 20-30 and 50-60 from each line and then insert a delimiter between them (# or | etc). eg input file 000000000131.12.20990000590425246363375670011200140406... (5 Replies)
Discussion started by: PradeepRed
5 Replies

4. Shell Programming and Scripting

cut and paste using awk

Hi i need a favour i have a file which has some trillions of records. The file is like this 11111000000000192831840914000000000000000000000000000 45789899090000000000000000011111111111111111111111111 I want to cut specific postions in each line like cut1-3 and assisgn it to a variable and... (5 Replies)
Discussion started by: richa2.m
5 Replies

5. UNIX for Dummies Questions & Answers

cut and paste from two tables

Hello, I want to be able to cut and paste columns from two tables in one command. Presently I do the following: cut -f 1,3-6,9 table1.in > table1.out cut -f 7,6,1-3 table2.in > table2.out paste table1.out -d '\t' table2.out > MergedTable.out Is there a better way to do this? ... (1 Reply)
Discussion started by: Gussifinknottle
1 Replies

6. Shell Programming and Scripting

cut and paste?

hi, I have a file with content like this for an employee: EmployeeID 101 Day_type, day vacation,1/2/2009 sick day, 3/2/2009 personal day, 4/5/2009 jury duty day, 5/5/2009 how do I make the result to show: EmployeeID,Day_type,day 101,vacation,1/2/2009 101,sick day,... (6 Replies)
Discussion started by: jbchen
6 Replies

7. UNIX for Dummies Questions & Answers

Cut paste from one file to other

Hello, I am working on unix for the first time. I have to write a shell script where i want to cut paste from one file to other. File "1234.abc" is 03,12345555 16,936,x,x,120 16,936,x,x,100 49,12345555 03,12347710 16,936,x,x,115 16,936,x,x,122 49,12347710 03,12342222... (9 Replies)
Discussion started by: swapsb
9 Replies

8. Shell Programming and Scripting

need help with cut and paste command

I have a file which contains 3 fields separated by tabs example andrew kid baker I need to swap kid and baker using cut and paste commands how is this to be done? Thanks (3 Replies)
Discussion started by: drew211
3 Replies

9. Shell Programming and Scripting

Issue with cut and paste

let i have A file and B file A has contains 4 fields as below ---------------- f1 f2 f3 f4 B file consists of 5 fields as below -------------------- f5 f6 f7 f8 f9 need to display as below output: f5 f1 f3 f8 f9 (2 Replies)
Discussion started by: ANSHUMAN1983
2 Replies

10. Shell Programming and Scripting

Problem in cut or paste

Hello, I have some problem in cut or paste command for my text data. Input1.txt : I use cut command : cut -d ' ' -f1 Input1.txt > result.txt result.txt : Then, I use paste command to merge result.txt. paste -d ' ' result.txt Input1.txt > output.txt output.txt showed : I use cut... (1 Reply)
Discussion started by: awil
1 Replies
exit(1) 							   User Commands							   exit(1)

NAME
exit, return, goto - shell built-in functions to enable the execution of the shell to advance beyond its sequence of steps SYNOPSIS
sh exit [n] return [n] csh exit [ ( expr )] goto label ksh *exit [n] *return [n] DESCRIPTION
sh exit will cause the calling shell or shell script to exit with the exit status specified by n. If n is omitted the exit status is that of the last command executed (an EOF will also cause the shell to exit.) return causes a function to exit with the return value specified by n. If n is omitted, the return status is that of the last command exe- cuted. csh exit will cause the calling shell or shell script to exit, either with the value of the status variable or with the value specified by the expression expr. The goto built-in uses a specified label as a search string amongst commands. The shell rewinds its input as much as possible and searches for a line of the form label: possibly preceded by space or tab characters. Execution continues after the indicated line. It is an error to jump to a label that occurs between a while or for built-in command and its corresponding end. ksh exit will cause the calling shell or shell script to exit with the exit status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the exit status is that of the last command executed. When exit occurs when executing a trap, the last command refers to the command that executed before the trap was invoked. An end-of-file will also cause the shell to exit except for a shell which has the ignoreeof option (See set below) turned on. return causes a shell function or '.' script to return to the invoking script with the return status specified by n. The value will be the least significant 8 bits of the specified status. If n is omitted then the return status is that of the last command executed. If return is invoked while not in a function or a '.' script, then it is the same as an exit. On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways: 1. Variable assignment lists preceding the command remain in effect when the command completes. 2. I/O redirections are processed after variable assignments. 3. Errors cause a script that contains them to abort. 4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari- able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not performed. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
break(1), csh(1), ksh(1), sh(1), attributes(5) SunOS 5.10 15 Apr 1994 exit(1)
All times are GMT -4. The time now is 12:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy