Sponsored Content
Full Discussion: Adding text into file
Top Forums Shell Programming and Scripting Adding text into file Post 302402635 by durden_tyler on Wednesday 10th of March 2010 08:43:58 AM
Old 03-10-2010
Code:
$
$ cat -n f3
     1  2 20008 2003-08-26
     2  2 20032 2003-08-26
     3  2 20041 2003-08-26
     4  2 20037 2003-08-26
     5  2 20050 2003-08-26
     6  6 20 2005-04-25
     7  6 10 2005-04-25
     8  2 767 2007-06-04
     9  2 768 2007-06-04
    10  2 1744 2009-09-17
$
$ perl -lne 'split/[- ]/ and print "cust=[$_[0]]\tagent=[$_[1]]\ts_date=[",substr($_[2],2),"$_[3]$_[4]]"' f3
cust=[2]        agent=[20008]   s_date=[030826]
cust=[2]        agent=[20032]   s_date=[030826]
cust=[2]        agent=[20041]   s_date=[030826]
cust=[2]        agent=[20037]   s_date=[030826]
cust=[2]        agent=[20050]   s_date=[030826]
cust=[6]        agent=[20]      s_date=[050425]
cust=[6]        agent=[10]      s_date=[050425]
cust=[2]        agent=[767]     s_date=[070604]
cust=[2]        agent=[768]     s_date=[070604]
cust=[2]        agent=[1744]    s_date=[090917]
$
$

tyler_durden

And another:

Code:
$
$ perl -lne '/(\d+) (\d+) \d\d(\d\d)-(\d\d)-(\d\d)/ and print "cust=[$1]\tagent=[$2]\ts_date=[$3$4$5]"' f3
cust=[2]        agent=[20008]   s_date=[030826]
cust=[2]        agent=[20032]   s_date=[030826]
cust=[2]        agent=[20041]   s_date=[030826]
cust=[2]        agent=[20037]   s_date=[030826]
cust=[2]        agent=[20050]   s_date=[030826]
cust=[6]        agent=[20]      s_date=[050425]
cust=[6]        agent=[10]      s_date=[050425]
cust=[2]        agent=[767]     s_date=[070604]
cust=[2]        agent=[768]     s_date=[070604]
cust=[2]        agent=[1744]    s_date=[090917]
$
$

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding Text To each line of a file

How would I add text to the beginning of each line in a text file in a script right after the file is created from another text file. (4 Replies)
Discussion started by: cubs0729
4 Replies

2. Shell Programming and Scripting

adding text to a file between lines

Suppose content of my first file: first line second line third line How can i insert text between "first line" & "second Iline" Any help?????/ (7 Replies)
Discussion started by: bishweshwar
7 Replies

3. Shell Programming and Scripting

Adding specific text and spaces to each line in a text file

Hi, I wanted to add specific text to each row in a text file containing three rows. Example: 0 8 7 6 5 5 7 8 9 0 7 9 7 8 9 0 1 2 And I want to add a 21 at the beginning of the first row, and blank spaces at the beginning of the second two rows. To get this: 21 0 8 7 6 5 5 7 8... (4 Replies)
Discussion started by: hertingm
4 Replies

4. Shell Programming and Scripting

Adding a delimiter to a text file

Im writing a KSH script to read a simple text file and add a delimiter. Ive written the following script but it runs very slow. I initially used the cut command to substring the input record then switched to this version using awk to substring... both run too slow. Any ideas how to make this more... (2 Replies)
Discussion started by: lock
2 Replies

5. Shell Programming and Scripting

adding text to a file

Hi All I am making a script in which.I have a problem i try to discribe. File1 content need to be append in file 2 but such as if content already exist then dont add. File1 IS Like this myname yourname hername hisname File2 %AddNameHere myname yourname hername hisname (3 Replies)
Discussion started by: aliahsan81
3 Replies

6. Shell Programming and Scripting

Adding Text To Middle Of File

Hi I am trying to write a bash script to add a line of text to the middle of a file. The way I worked it out was to calculate the number of lines and divide by 2. The file I am using is called newfile and it just contains lines of data. The new file I have created I have called midfile and... (7 Replies)
Discussion started by: BundBash
7 Replies

7. Shell Programming and Scripting

[bash help]Adding multiple lines of text into a specific spot into a text file

I am attempting to insert multiple lines of text into a specific place in a text file based on the lines above or below it. For example, Here is a portion of a zone file. IN NS ns1.domain.tld. IN NS ns2.domain.tld. IN ... (2 Replies)
Discussion started by: cdn_humbucker
2 Replies

8. Shell Programming and Scripting

adding a line to a text file

I have a tab delimited text file, id name distance 1 3325167 0.334561754018 2 3290488 0.389444269458 3 3288794 0.392312701782 4 3347602 0.392532202097 5 3295355 0.394394169485 I need to add a line after the header line. The first and third field of... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

9. Shell Programming and Scripting

editing line in text file adding number to value in file

I have a text file that has data like: Data "12345#22" Fred ID 12345 Age 45 Wilma Dino Data "123#22" Tarzan ID 123 Age 33 Jane I need to figure out a way of adding 1,000,000 to the specific lines (always same format) in the file, so it becomes: Data "1012345#22" Fred ID... (16 Replies)
Discussion started by: say170
16 Replies

10. UNIX for Dummies Questions & Answers

About adding users from a text file using bash

hello, I try to add users from a text file with this form: username:groupename:homedir first i extract data which is separated by ":" then i use useradd to add users/groups. but,,, my code doesn't works : #!/bin/bash echo "give me a text file: " read dir # control if... (2 Replies)
Discussion started by: ref012
2 Replies
PTHREAD_RWLOCK_UNLOCK(P)				     POSIX Programmer's Manual					  PTHREAD_RWLOCK_UNLOCK(P)

NAME
pthread_rwlock_unlock - unlock a read-write lock object SYNOPSIS
#include <pthread.h> int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); DESCRIPTION
The pthread_rwlock_unlock() function shall release a lock held on the read-write lock object referenced by rwlock. Results are undefined if the read-write lock rwlock is not held by the calling thread. If this function is called to release a read lock from the read-write lock object and there are other read locks currently held on this read-write lock object, the read-write lock object remains in the read locked state. If this function releases the last read lock for this read-write lock object, the read-write lock object shall be put in the unlocked state with no owners. If this function is called to release a write lock for this read-write lock object, the read-write lock object shall be put in the unlocked state. If there are threads blocked on the lock when it becomes available, the scheduling policy shall determine which thread(s) shall acquire the lock. If the Thread Execution Scheduling option is supported, when threads executing with the scheduling policies SCHED_FIFO, SCHED_RR, or SCHED_SPORADIC are waiting on the lock, they shall acquire the lock in priority order when the lock becomes available. For equal prior- ity threads, write locks shall take precedence over read locks. If the Thread Execution Scheduling option is not supported, it is imple- mentation-defined whether write locks take precedence over read locks. Results are undefined if any of these functions are called with an uninitialized read-write lock. RETURN VALUE
If successful, the pthread_rwlock_unlock() function shall return zero; otherwise, an error number shall be returned to indicate the error. ERRORS
The pthread_rwlock_unlock() function may fail if: EINVAL The value specified by rwlock does not refer to an initialized read-write lock object. EPERM The current thread does not hold a lock on the read-write lock. The pthread_rwlock_unlock() function shall not return an error code of [EINTR]. The following sections are informative. EXAMPLES
None. APPLICATION USAGE
None. RATIONALE
None. FUTURE DIRECTIONS
None. SEE ALSO
pthread_rwlock_destroy() , pthread_rwlock_rdlock() , pthread_rwlock_timedrdlock() , pthread_rwlock_timedwrlock() , pthread_rwlock_tryrd- lock() , pthread_rwlock_trywrlock() , pthread_rwlock_wrlock() , the Base Definitions volume of IEEE Std 1003.1-2001, <pthread.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 PTHREAD_RWLOCK_UNLOCK(P)
All times are GMT -4. The time now is 08:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy