Sponsored Content
Top Forums Shell Programming and Scripting BASH: Break line, read, break again, read again... Post 302520151 by SilversleevesX on Friday 6th of May 2011 02:17:34 AM
Old 05-06-2011
BASH: Break line, read, break again, read again...

...when the lines use both a colon and commas to separate the parts you want read as information.
Quote:
example.jpg:QVC,honeywell-labs.com,COM,blah,blah,blah,so-on,so-on,and so-on
The first version of this script used cut and other non-Bash-builtins, frequently, which made it nice and zippy with little more than average processor load in GNOME Terminal but, predictably, slow as a sloth on Valium and heavy on the CPU in Cygwin.
Code:
while read 'line';
do
n=$(echo $line)
file=$(echo -ne $n | cut -d: -f1)
tags=$(echo -ne $n | cut -d: -f2)
cate=$(echo -ne $tags | cut -d, -f1)
cred=$(echo -ne $tags | cut -d, -f2)
sour=$(echo -ne $tags | cut -d, -f3)
writ=$(echo -ne $tags | cut -d, -f4)
trans=$(echo -ne $tags | cut -d, -f5)
fixid=$(echo -ne $tags | cut -d, -f6)
objnm=$(echo -ne $tags | cut -d, -f7)
locn=$(echo -ne $tags | cut -d, -f8)
fname=`basename "$file"`
echo -e "Working on file $fname now."

I decided I wanted it to work faster, whatever it was run in.

Recently, I came across a line -- you might call it a command 'pair' -- in another script
Code:
exec 5<foo.txt
while IFS="," read -u5

for which I got help either here or on LQ. I've applied it to other scripts, and I've seen, yet again, the difference in speed a builtin often makes over an external binary. All those scripts had something in common, however: the data they read in was separated by a single delimiter, a colon or a comma, but not one of the former and several of the latter, as in my example above.

Re-working it with as much as I can get my mind around in terms of the 'read' and 'exec' commands, with only the most modest looking about on coder/scripter bulletin-board sites etc., I still can't get it to split the data in the $tags variable.

It looks like my approach is all wrong. So what would be a more useful way to go about it, keeping in mind that I want to employ more (all, if possible) builtins and stay away from "/bin" externals.

BZT
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

TO break a line

hi All, Have a doubt in ksh..Am not familiar with arrays but i have tried out a script.. plzzzzz correct me with the script My i/p File is: (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = 192.168.2.2) (Port = 1525) ) ) (CONNECT_DATA = (SID = TESTDB1) ) ) ... (7 Replies)
Discussion started by: aajan
7 Replies

2. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

3. Shell Programming and Scripting

break while loop in BASH

Hi gurus, I have the following part of code which I am using for treating input #!/bin/bash while ]; do arg=$1; shift case $arg in -u) users="$1" shift ;; -g) groups="$1" shift ;; ... (4 Replies)
Discussion started by: wakatana
4 Replies

4. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

5. Shell Programming and Scripting

Insert line break

Dear All, thanks in advance input file 410530AAANNNNNAAA410530JJJJJJYYYY410530PPPPPAAAAAA........... I want output like 410530AAANNNNNAAA 410530JJJJJJYYYY 410530PPPPPAAAAAA Thanks (10 Replies)
Discussion started by: The_Archer
10 Replies

6. Shell Programming and Scripting

Multiple line break

Hi, We had an issue with one file. Each line in the file is a record in which there will be 6 fields each separated by ; Problem is some lines are broken into pieces. like a;b; c; d; e;f instead of a;b;c;d;e;f I have filtered out all the broken lines from the original file and wrote to... (6 Replies)
Discussion started by: anjuvr
6 Replies

7. UNIX for Dummies Questions & Answers

VI Line Break?

So I'm in a Unix class and our assignment was to go into VI and write a script to make this file tree. At the end of it, I'd like it to echo "This is the file tree you've created" then a line break, then . But I'm not sure as to who to do it. Is there a way for when I run it (./filesystem), the... (4 Replies)
Discussion started by: bbowers
4 Replies

8. Shell Programming and Scripting

How to break the line to the one above?

Hello everyone! I'm trying to make the below file1 look like file2, can anyone help? Basically I just hit backspace on every line that starts with a number. Thanks! file1: THIS#IS-IT1 4 THIS#IS-IT2 3 THIS#IS-IT3 2 THIS#IS-IT4 1 Result > file2: (4 Replies)
Discussion started by: demmel
4 Replies

9. UNIX for Dummies Questions & Answers

Script to break up file (write new files) in bash

Hello experts, I need help writing individual files from a data matrix, with each new file being written every time there is a blank line: From this cat file.txt col1 col2 col3 6661 7771 8881 6661 7771 8881 6661 7771 8881 col1 col2 col3 3451 2221 1221... (6 Replies)
Discussion started by: torchij
6 Replies
FLVTOOL2(1)						      General Commands Manual						       FLVTOOL2(1)

NAME
flvtool2 - a manipulation tool for flash video files SYNOPSIS
flvtool2 [-ACDPUVaciklnoprstvx]...[-key:value]...in-path|stdin[out-path|stdout] DESCRIPTION
If out-path is omitted, in-path will be overwritten. In-path can be a single file, or a directory. If in-path is a directory, out-path has to be likewise, or can be omitted. Directory recursion is controlled by the -r switch. You can use stdin and stdout keywords as in- and out-path for piping or redirecting. Chain commands like that: -UP (updates FLV file than prints out meta data) COMMANDS
-A Adds tags from -t tags-file -C Cuts file using -i inpoint and -o outpoint -D Debugs file (writes a lot to stdout) -H Helpscreen will be shown -P Prints out meta data to stdout -U Updates FLV with an onMetaTag event SWITCHES
-a Collapse space between cut regions -c Compatibility mode calculates some onMetaTag values differently -key:value Key-value-pair for onMetaData tag (overwrites generated values) -i timestamp Inpoint for cut command in miliseconds -k Keyframe mode slides onCuePoint(navigation) tags added by the add command to nearest keyframe position -l Logs FLV stream reading to stream.log in current directory -n Number of tag to debug -o timestamp Outpoint for cut command in miliseconds -p Preserve mode only updates FLVs that have not been processed before -r Recursion for directory processing -s Simulation mode never writes FLV data to out-path -t path Tagfile (MetaTags written in XML) -v Verbose mode -x XML mode instead of YAML mode SEE ALSO
/usr/share/doc/flvtool2/examples/tags.xml http://www.inlet-media.de/flvtool2 AUTHOR
flvtool2 was written by Norman Timmler <norman.timmler@inlet-media.de> This manual page was written by Todd Troxell <ttroxell@debian.org>, for the Debian project (but may be used by others). August 24, 2007 FLVTOOL2(1)
All times are GMT -4. The time now is 11:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy