Sponsored Content
Top Forums Shell Programming and Scripting embed a separator after each word in a text file Post 302574590 by durden_tyler on Thursday 17th of November 2011 04:37:45 PM
Old 11-17-2011
Here are a couple of Perl one-liners -

Code:
$
$ cat f41
The quick brown fox jumps over the lazy dog.
Mary had a little lamb.
Humpty Dumpty sat on a wall.
$
$
$ perl -plne 's/(\w+)/$1,/g' f41
The, quick, brown, fox, jumps, over, the, lazy, dog,.
Mary, had, a, little, lamb,.
Humpty, Dumpty, sat, on, a, wall,.
$
$
$ perl -plane '$_=join(", ",@F)' f41
The, quick, brown, fox, jumps, over, the, lazy, dog.
Mary, had, a, little, lamb.
Humpty, Dumpty, sat, on, a, wall.
$
$

As pointed out by vgersh99, you'll have to define the meaning of a "word".

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to substitute more than one word in a text file?

well i have this file here: <XML> <pregate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <system_c>HPREGATE</system_c> <trans_c>HSPG</trans_c> <trans_dt>20060105161333</trans_dt> <user_id_m></user_id_m> <func_c>C</func_c> </pregate> </XML> i want to... (2 Replies)
Discussion started by: forevercalz
2 Replies

2. Shell Programming and Scripting

Can a shell script pull the first word (or nth word) off each line of a text file?

Greetings. I am struggling with a shell script to make my life simpler, with a number of practical ways in which it could be used. I want to take a standard text file, and pull the 'n'th word from each line such as the first word from a text file. I'm struggling to see how each line can be... (5 Replies)
Discussion started by: tricky
5 Replies

3. Shell Programming and Scripting

[Bash]Attempting to Merge text from one file into another file at the line directly under a word

Hello, This is my first post on the forums. So I want to start by thanking anyone who is kind enough to read this post and offer advise. I hope to be an active contributor now that I've found these forums. I have an issue that I figure would be a good first post.. I have 2 text files... (5 Replies)
Discussion started by: efciem
5 Replies

4. UNIX for Dummies Questions & Answers

how to read the second word of a text file

Folks, how to read the second word of the first line from a text file. Text file does not have any delimiters in the line and has words at random locations. Basically the text file is a log and i want to capture a number that is in second position. Appreciate your help Venu (1 Reply)
Discussion started by: venu
1 Replies

5. Shell Programming and Scripting

extract a word from text file name

Hi i want to extract the word present before .txt in the text file. For example, Sample_ab_a.txt ----------> i need 'a' Sample_abc_b.txt -----------> i need 'b' Can anyone help me in getting the word extracted (5 Replies)
Discussion started by: Sindhuap
5 Replies

6. Shell Programming and Scripting

Add a word to Text file

Hello, I have a mysql text file. I want add word to it. Thanks for help. Sample sql file: ,'address','166 Warren Street, NY 12534'),(45215,26556,'phone','(518)811-4145'),(151426,15565,'listing_duration','address','122 Hom Street, NY... (6 Replies)
Discussion started by: hoo
6 Replies

7. UNIX for Dummies Questions & Answers

Add a word to Text file

Hello, I have a mysql text file. I want add a word to it. Thanks for help. Sample text: ,'address','166 Warren Street, NY 12534'),(45215,26556,'phone','(518)811-4145'),(151426,15565,'listing_duration' ,'address','233 Tan Street, CA... (1 Reply)
Discussion started by: hoo
1 Replies

8. Shell Programming and Scripting

How to insert a word into a text file?

Hi, I have a text file with one line having few words separated by space and I need to insert another word on "n"th column/field so that previous word should shift right (to n+1st column). how can I do that? It seems we can do using awk but unable to figure out. Please advise, thanks! ... (11 Replies)
Discussion started by: magnus29
11 Replies

9. Shell Programming and Scripting

Organizing text file by Capital Names (capital word ' ' capital word)

Hi I have a file passwd_exmpl that contains: root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync... (5 Replies)
Discussion started by: eladage
5 Replies

10. Programming

Embed text in C code

I hope c coding is ok here. I am fairly new at c coding. I simply want to embed some text in the executable. I tried this but can't find the text using Ghex. #include <stdio.h> const char * S = "andrew"; int main() { printf("Hello World!\n"); return 0; } (8 Replies)
Discussion started by: drew77
8 Replies
HASH_FILE(3)								 1							      HASH_FILE(3)

hash_file - Generate a hash value using the contents of a given file

SYNOPSIS
string hash_file (string $algo, string $filename, [bool $raw_output = false]) DESCRIPTION
PARAMETERS
o $algo - Name of selected hashing algorithm (i.e. "md5", "sha256", "haval160,4", etc..) o $filename - URL describing location of file to be hashed; Supports fopen wrappers. o $raw_output - When set to TRUE, outputs raw binary data. FALSE outputs lowercase hexits. RETURN VALUES
Returns a string containing the calculated message digest as lowercase hexits unless $raw_output is set to true in which case the raw binary representation of the message digest is returned. EXAMPLES
Example #1 Using hash_file(3) <?php /* Create a file to calculate hash of */ file_put_contents('example.txt', 'The quick brown fox jumped over the lazy dog.'); echo hash_file('md5', 'example.txt'); ?> The above example will output: 5c6ffbdd40d9556b73a21e63c3e0e904 SEE ALSO
hash(3), hash_hmac_file(3), hash_update_file(3), md5_file(3), sha1_file(3). PHP Documentation Group HASH_FILE(3)
All times are GMT -4. The time now is 05:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy