Sponsored Content
Top Forums Shell Programming and Scripting Non trivial file splitting, saving with variable filename Post 302821773 by samask on Saturday 15th of June 2013 01:30:40 PM
Old 06-15-2013
Hi,

It works beautifully, and it is amazingly fast!

The file names are written with a colon, which is not allowed on OS X:
dw:1.txt, is there a way to have a dash instead, like
dw-1.txt?

I must add that I had to take away the Chapter part,
becasue many chapter headings do not include that word in their text.

So, I have been using:

awk '/\* /{close(f); p=x; f=x} /CITE-KEY/{f=tolower($2) ".txt"; $0=p$0 } !f{p=p $0 ORS} f{print >f}' file

I tried:

awk '/\* {close(f); p=x; f=x} /CITE-KEY/{f=tolower($2) ".txt"; $0=p$0 } !f{p=p $0 ORS} f{print >f}' file

But it throws:
Code:
awk: syntax error at source line 1
 context is
    /\* {close(f); p=x; f=x} >>>  /CITE-KEY/{ <<<
awk: bailing out at source line 1

Thank you so much. So much elegance in Awk. Truly inspiring.

Last edited by samask; 06-15-2013 at 02:43 PM.. Reason: Correct text
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Moving files by splitting the path embedded in the filename

Hello All. I am having a directory /tmp/rahul which contains many files in the format @#home@#rahul@#programs@#script.pl where /home/rahul/programs is the directory where the script.pl file is to be placed. I have many files in this format. What i want is a script which read these... (7 Replies)
Discussion started by: rahulrathod
7 Replies

2. UNIX for Dummies Questions & Answers

File Transfer that is not so trivial I guess

I have three computers A, B and C. To login to B and C I should use A because it has a SSH key. I don't have any other way of accessing these two computers. Now, if I need to transfer a file between B and C, I am unable to find a way that would work... because I don't know how to authenticate... (1 Reply)
Discussion started by: Legend986
1 Replies

3. Shell Programming and Scripting

Piping to a file and setting filename using a variable

Hi all, I would like to send the output of a line in a ksh script to a file, but I need to name the file using a predefined variable: ls -l > $MYVAR.arc But what is the correct syntax for achieving this? I can't seem to find the correct syntax for giving the file an extension. Any... (8 Replies)
Discussion started by: mandriver
8 Replies

4. UNIX for Dummies Questions & Answers

saving command output to a variable

Hello, I have a shell script containing a command string in the following format: command1 | command2 | cut -c9-16 The output from this is a record number (using characters 9-16 of the original output string) e.g. ORD-1234 I wish to save this value to a variable for use in later commands... (4 Replies)
Discussion started by: philjo
4 Replies

5. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

6. Shell Programming and Scripting

Trouble saving variable

Hi, I have problems when you save a variable of a command. I have put the following line: CONEXION_BAGDAD = $ (grep-c "Please login with USER and PASS" $ LOG_FILE_BAGDAD) But I returned the following error: syntax error at line 67: `CONEXION_BAGDAD = $ 'unexpected Because it can happen?... (2 Replies)
Discussion started by: danietepa
2 Replies

7. Homework & Coursework Questions

Matlab help! Reading in a file with a variable filename

1. The problem statement, all variables and given/known data: I want to read in a file, and plot the data in matlab. However, I do not like hardwiring filenames into my codes, so I always give the user the option to specify what the filename is. I am pretty inexperienced with matlab, so I have no... (0 Replies)
Discussion started by: ds7202
0 Replies

8. Shell Programming and Scripting

Trivial perl doubt about FILE

Hi, In the following perl code: #!/usr/bin/perl -w if (open(FILE, "< in_file")) { while (<FILE>) { chomp($_); if ($_ =~ /patt$/) { my $f = (split(" ", $_)); print "$f\n"; } } close FILE; } Why changing the "FILE" as... (4 Replies)
Discussion started by: royalibrahim
4 Replies

9. Open Source

Splitting files using awk and reading filename value from input data

I have a process that requires me to read data from huge log files and find the most recent entry on a per-user basis. The number of users may fluctuate wildly month to month, so I can't code for it with names or a set number of variables to capture the data, and the files are large so I don't... (7 Replies)
Discussion started by: rbatte1
7 Replies

10. Shell Programming and Scripting

Saving Mod in a variable

Hello Experts, In one of my shell script, I've been trying to calculate mod and saving it in a variable, below is what I have tried but it isn't working. Any help appreciated!!! #!/bin/bash num1=4 num2=3 echo "Number one is $num1" echo "Number two is $num2" mod_final=$(( echo "num1%num2"... (7 Replies)
Discussion started by: mukulverma2408
7 Replies
resgen(resgen 1.0)														resgen(resgen 1.0)

NAME
resgen, resgen2 - Mono/CLI Resource Generator SYNOPSIS
resgen source.ext [dest.ext] resgen /compile source.ext[,dest.resources] [...] resgen2 DESCRIPTION
Convert a resource file from one format to another. The currently supported formats are text, resources, resx and po. .txt, .text Used to process text files, the format of the text file is of the form: key=value The value argument can contain special characters as long as they are escaped. The escape sequences currently supported are , , , \ (to get the escape sequence itself) and with resgen2 unicode escape sequences are supported with the uXXXX escape sequence, where XXXX is a four digit number. Lines that start with the # or ; character are considered comments and ignored. '.resources' This is the binary file format implemented by the System.Resources.ResourceReader class, part of mscorlib.dll '.resx' This is the binary file format implemented by the System.Resources.ResXResourceReader class. This class is not part of mscor- lib.dll, this class is part of System.Windows.Forms. '.po'. PO files are the source files used by the Unix gettext infrastructure that is typically used to internationalize applications. Lines starting with the '#' character are comment lines. The file contains many instance of strings like this: msgid KEY msgstr VALUE The KEY is typically the string to translate and the VALUE is the translation. On PO files instead of using codes as the KEY (as it is customary with resource files) the KEY is typically a complete english message that applications embed in their source code and will be used as a fallback if no translation resources are used. Since resources are key value pairs, the extended features in PO files are not supported (plurals and support for N-cases). To learn more about the po file format, use your info browser and point it to the "(gettext)PO Files" node. If the destination file is not specified, source.resources will be used. The /compile option takes a list of .resX or .txt files to convert to the output file name. OPTIONS
-compile This switch instructs resgen to compile multiple files. It must appear before any resources are specified on the command line. -usesourcepath This option is only available for resgen2, and it instructs resgen to resolve relative paths using the directory of the resx file as current directory. FILES
This program will load referenced assemblies from the Mono assembly cache. MAILING LISTS
Visit http://lists.ximian.com/mailman/listinfo/mono-devel-list for details. WEB SITE
Visit: http://www.mono-project.com for details SEE ALSO
mcs(1),mono(1),mono-config(5). resgen(resgen 1.0)
All times are GMT -4. The time now is 04:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy