Sponsored Content
Top Forums Shell Programming and Scripting Concatenate strings retrieved from a file and write it into another file Post 302540928 by archana.n on Friday 22nd of July 2011 03:22:03 AM
Old 07-22-2011
Concatenate strings retrieved from a file and write it into another file

Hi,

I have a file files.txt containing data as below:
Code:
abc;xyz
uvw;pqr
123;456

I want to develop strings like below using the above data and write them into another file:
Code:
www/xxx/abc/yyy/xyz
www/xxx/uvw/yyy/pqr
www/xxx/123/yyy/456

All this needs to be done through .sh file.

Could you please help?

Last edited by Franklin52; 07-22-2011 at 07:01 AM.. Reason: Please use code tags for code and data samples, thank you
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to concatenate two strings or several strings into one string in B-shell?

like connect "summer" and "winter" to "summerwinter"? Can anybody help me? thanks a lot. (2 Replies)
Discussion started by: fontana
2 Replies

2. UNIX for Dummies Questions & Answers

Concatenate Strings

Hi Friends, I have a requirement I need to concatenate the below two strings. String 1 = /@jobid_at_ String 2 = value stored in ORACLE_SID String 3 = string1 concatenated with String 2. Please let me know how should i do it in UNIX. Thanks, (2 Replies)
Discussion started by: diva_thilak
2 Replies

3. Shell Programming and Scripting

Execute command on first column (filename) retrieved from a file

Hi, I have a file abcd.txt which in turn contains 20 file names as column 1. Now I want to run a command "ct co -nc" / "cp" / "mv" on each of these $1 column content i.e. on each of the 20 file names. How can do this using a script so that I need not run the same command 20 times... (13 Replies)
Discussion started by: royzlife
13 Replies

4. Shell Programming and Scripting

How to write a script to extract strings from a file.

Hello fourm members, I want to write a script to extarct paticular strings from the all type of files(.sh files,logfiles,txtfiles) and redirect into a log file. example: I have to find the line below in the script and extract the uname and Pwds. sqsh -scia2007 -DD0011uw01 -uciadev... (5 Replies)
Discussion started by: rajkumar_g
5 Replies

5. UNIX for Dummies Questions & Answers

concatenate strings

if i use echo "ravi" echo "sankar" it showing output ravi sankar but i want output as ravi sankar remember sankar should be in another echo statement only (2 Replies)
Discussion started by: shankr3
2 Replies

6. Web Development

Concatenate Strings

hi..:) this is my sample part of my program.. $csv_output .= $row.",". $row.",". $row.",". $row.",". $row.",". ... (2 Replies)
Discussion started by: Jeneca
2 Replies

7. Shell Programming and Scripting

Search for string in a file, extract two another strings and concatenate to a variable

I have a file with <suit:run date="Trump Tue 06/19/2012 11:41 AM EDT" machine="garg-ln" build="19921" level="beta" release="6.1.5" os="Linux"> Need to find word "build" then extract build number, which is 19921 also release number, which is 6.1.5 then concatenate them to one variable as... (6 Replies)
Discussion started by: garg
6 Replies

8. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

9. UNIX for Beginners Questions & Answers

Use strings from nth field from one file to match strings in entire line in another file, awk

I cannot seem to get what should be a simple awk one-liner to work correctly and cannot figure out why. I would like to use patterns from a specific field in one file as regex to search for matching strings in the entire line ($0) of another file. I would like to output the lines of File2 which... (1 Reply)
Discussion started by: jvoot
1 Replies
STRTOK(3)						     Linux Programmer's Manual							 STRTOK(3)

NAME
strtok, strtok_r - extract tokens from strings SYNOPSIS
#include <string.h> char *strtok(char *str, const char *delim); char *strtok_r(char *str, const char *delim, char **saveptr); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): strtok_r(): _SVID_SOURCE || _BSD_SOURCE || _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE DESCRIPTION
The strtok() function parses a string into a sequence of tokens. On the first call to strtok() the string to be parsed should be specified in str. In each subsequent call that should parse the same string, str should be NULL. The delim argument specifies a set of characters that delimit the tokens in the parsed string. The caller may specify different strings in delim in successive calls that parse the same string. Each call to strtok() returns a pointer to a null-terminated string containing the next token. This string does not include the delimiting character. If no more tokens are found, strtok() returns NULL. A sequence of two or more contiguous delimiter characters in the parsed string is considered to be a single delimiter. Delimiter charac- ters at the start or end of the string are ignored. Put another way: the tokens returned by strtok() are always nonempty strings. The strtok_r() function is a reentrant version strtok(). The saveptr argument is a pointer to a char * variable that is used internally by strtok_r() in order to maintain context between successive calls that parse the same string. On the first call to strtok_r(), str should point to the string to be parsed, and the value of saveptr is ignored. In subsequent calls, str should be NULL, and saveptr should be unchanged since the previous call. Different strings may be parsed concurrently using sequences of calls to strtok_r() that specify different saveptr arguments. RETURN VALUE
The strtok() and strtok_r() functions return a pointer to the next token, or NULL if there are no more tokens. CONFORMING TO
strtok() SVr4, POSIX.1-2001, 4.3BSD, C89, C99. strtok_r() POSIX.1-2001. BUGS
Be cautious when using these functions. If you do use them, note that: * These functions modify their first argument. * These functions cannot be used on constant strings. * The identity of the delimiting character is lost. * The strtok() function uses a static buffer while parsing, so it's not thread safe. Use strtok_r() if this matters to you. EXAMPLE
The program below uses nested loops that employ strtok_r() to break a string into a two-level hierarchy of tokens. The first command-line argument specifies the string to be parsed. The second argument specifies the delimiter character(s) to be used to separate that string into "major" tokens. The third argument specifies the delimiter character(s) to be used to separate the "major" tokens into subtokens. An example of the output produced by this program is the following: $ ./a.out 'a/bbb///cc;xxx:yyy:' ':;' '/' 1: a/bbb///cc --> a --> bbb --> cc 2: xxx --> xxx 3: yyy --> yyy Program source #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { char *str1, *str2, *token, *subtoken; char *saveptr1, *saveptr2; int j; if (argc != 4) { fprintf(stderr, "Usage: %s string delim subdelim ", argv[0]); exit(EXIT_FAILURE); } for (j = 1, str1 = argv[1]; ; j++, str1 = NULL) { token = strtok_r(str1, argv[2], &saveptr1); if (token == NULL) break; printf("%d: %s ", j, token); for (str2 = token; ; str2 = NULL) { subtoken = strtok_r(str2, argv[3], &saveptr2); if (subtoken == NULL) break; printf(" --> %s ", subtoken); } } exit(EXIT_SUCCESS); } /* main */ SEE ALSO
index(3), memchr(3), rindex(3), strchr(3), strpbrk(3), strsep(3), strspn(3), strstr(3), wcstok(3) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2008-10-29 STRTOK(3)
All times are GMT -4. The time now is 02:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy