Sponsored Content
Top Forums Shell Programming and Scripting Read line, issue with leading - and {}'s Post 302932514 by sea on Thursday 22nd of January 2015 06:33:29 AM
Old 01-22-2015
@ Corona:
The leading 'dash' produces an error like (Just the same way as printf does :: was the first/last i could find when scrolling up from yesterdays terminal output):
Code:
# |                                                                                                              | #
# | * Thu Dec 18 2014 - Simon A. Erat - erat.simon@gmail.com - 0.6.4-0                                           | #
/bin/tui-printf: Invalid Option --  

tui-printf (1.4)
tui-printf
Usage: 	tui-printf [options] [arguments]
	tui-printf		Prints up to 3 arguments. 
			1: Left
			2: Left, Right
			3: Left, Center, Right
Arguments will tell tui-printf if and where to colorize, or if to do a linebreak.

Obviously this error appears as many times there is a leading dash, which is required by the specfile to list items.
Though, its more thought to print 'simple' text files, rather than 'scripts' like this.

--> @ Jim: Yes.
Hope xargs preserves argument strings?
Anyway, i will see what happens.

@ MadeInGermany
The % was in some way the least of the issues , but i try it 'that' way and see if it fixes the alignment.

Thinking...
Since its tui-printf issueing the leading dash, as that indicates an option/argument for tui-printf uses getopts to parse them, it could be a good idea to catch this (the leading dash) in tui-printf.
So another, fetching wrong option to catch in a tempvar and reuse that tempvar in the final output (354) again, hopeing there will be no splitting up, though i could just pass the tempvar again, and let itself handle it again when the string matches on the line...

But first, i'll do what you suggested.

---------- Post updated at 11:43 ---------- Previous update was at 11:03 ----------

With the changes from MadeInGermany (only), i get (regardles of '%s' or "%s" or even echo -n "-teststring"):
Code:
tui-cat /home/sea/prjs/tui/tui.spec 
\r\033[0m# | Name:        tui                                                                                             | #\033[0m\n\033[0m\r\033[0m# | Version:     0.6.8                                                                                           | #\033[0m\n\033[0m\r\033[0m# | Release:     9%%{?dist}                                                                                      | #\033[0m\n\033[0m\r\033[0m# | Summary:     A line based Text User Interface framework for scripts                                          | #

@ Jim
Now i dont get any of the dashes to see.
They are part of the output, so i want to preserve them for the output, they just keep interfeering with:
Code:
printf "-teststring"
bash: printf: -t: Invalid Option
printf: Use: printf [-v var] Format [Argumente]


Figured, ty M.I.G., that tui-echo didnt print "This is 100%" well, so i've added the escaping from tui-cat to tui-printf, which does the tui-echo output, which is again used by tui-cat. Easy huh Smilie

Anyway, since that works quite good, i can finaly be precice on my question:

I need to know a way so i can pass a string to a command, so it prints a leading dash without failing, give it also has the 'power' of printf.
Or something that helps to preserve the leading dash for the output, without crashing the expected output, and to print the escape char for the leading dash, as shown in first post.

Any further ideas please?
Thank you in advance.

---------- Post updated at 12:33 ---------- Previous update was at 11:43 ----------

For the leading dash, i put in a single empty spacechar and renamed line to content.
Tui-cat now uses this:
Code:
			if [[ -f "$arg" ]]
			then 	while read content
				do	[[ "-" = "${content:0:1}" ]] && \
						content=" ${content}"
					tui-echo "${content}"
				done<"$arg"
			else	tui-status 1 "File not found: $arg"
			fi

As of now, the % fix is:
Code:
	# Escape '%'
	output=$(echo "${COLOR_LINE_START}${BORDER_LEFT}${COLOR_LINE_IDENT} ${FIRST}${SECOND}${THIRD} ${COLOR_LINE_CLOSE}${BORDER_RIGHT}${COLOR_LINE_END}"|$SED s,'%','%%',g)
	printf "$output"

So me now have only one remaining issue:
Code:
# | mkdir -p     %{buildroot}%{_bindir}/                      %{buildroot}%{_mandir}/man1                        | #
# |                               %{buildroot}%{_sysconfdir}/%{name}/                      %{buildroot}%{_syscon | #
# |                 fdir}/profile.d/                      %{buildroot}%{_datarootdir}/%{name}/themes             | #
# |                          %{buildroot}%{_docdir}/%{name} 		     %{buildroot}%{_sysconfdir}/bash_completion.d/ | #

Should actualy look like (keep format/idention, show the backslash):
Code:
mkdir -p     %{buildroot}%{_bindir}/ \
                     %{buildroot}%{_mandir}/man1 \
                     %{buildroot}%{_sysconfdir}/%{name}/ \
                     %{buildroot}%{_sysconfdir}/profile.d/ \
                     %{buildroot}%{_datarootdir}/%{name}/themes \
                     %{buildroot}%{_docdir}/%{name} \
		     %{buildroot}%{_sysconfdir}/bash_completion.d/

My best guess is (in tui-printf):
Code:
# Change/switch leading space-dash
	[[ " -" = "${FIRST:0:2}" ]] && \
		FIRST="${FIRST:1} " # Trailing space is a _MUST_ to keep alignment intact, as it got counted when the space was leading
	# Escape trailing backslash, from whichever argument passed
	echo "$FIRST" | grep -q "\\"$ && \
		FIRST="${FIRST}\\\\"
	echo "$SECOND" | grep -q "\\"$ && \
		SECOND="${SECOND}\\\\"
	echo "$THIRD" | grep -q "\\"$ && \
		THIRD="${THIRD}\\\\"
	
	# Escape '%'
	output=$(echo "${COLOR_LINE_START}${BORDER_LEFT}${COLOR_LINE_IDENT} ${FIRST}${SECOND}${THIRD} ${COLOR_LINE_CLOSE}${BORDER_RIGHT}${COLOR_LINE_END}"|$SED s,'%','%%',g)
	
	# The actual output
	printf "$output"

My other attempt also doesnt seem to work (in tui-cat):
Code:
# Tailing backslash
	[[ ! -z "$content" ]] && \
		[[ "\\" = "${content:0:(-1)}" ]] && \
		content="${content}\\\\"

But still dont even see the tailing \...
Any ideas
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

while read loop preserving leading whitespace

Hi all, I've been trying to get this to work for ages to no avail. I've searched this site and googled but cannot find a satisfactory answer. I've got a while loop, like this while read line do echo "$line" done < file_name Now, my problem is that most of the lines in the file... (3 Replies)
Discussion started by: zazzybob
3 Replies

2. Shell Programming and Scripting

remove leading spaces from a line

Hi friends I need some help, I have a file which looks as follows TEMP 014637065 014637065 517502 517502 RTE 517502 517502 RTE AWATER_TEST 12325 23563 588323 2323 5656 32385 23235635 ANOTHER_TEST 12 5433 FTHH 5653 833 TEST 123 123 3235 5353 353 53 35 353 535 3 YTERS GJK JKLS ... (6 Replies)
Discussion started by: lijojoseph
6 Replies

3. Shell Programming and Scripting

ksh - read file with leading spaces

Hi, Could someone has any suggestions on this? When read a line from a file, I need to check the first char in the line, it could be a space or any char. But the leading spaces are removed by read. Thanks. (2 Replies)
Discussion started by: momi
2 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

While loop read line Issue

Hi I am using while loop, below, to read lines from a very large file, around 400,000 rows. The script works fine until around line 300k but then starts giving incorrect result. I have tried running the script with a smaller data set and it works fine. I made sure to include the line where... (2 Replies)
Discussion started by: saurabhkumar198
2 Replies

6. Shell Programming and Scripting

Multi Line 'While Read' command issue when using sh -c

Hi, I'm trying to run the following command using sh -c ie sh -c "while read EachLine do rm -f $EachLine ; done < file_list.lst;" It doesn't seem to do anything. When I run this at the command line, it does remove the files contained in the list so i know the command works ie... (4 Replies)
Discussion started by: chrispward
4 Replies

7. Shell Programming and Scripting

while read LINE issue

Hi, This is the script and the error I am receiving Can anyone please suggest ? For the exmaple below assume we are using vg01 #!/bin/ksh echo "##### Max Mount Count Fixer #####" echo "Please insert Volume Group name to check" read VG lvs |grep $VG | awk {'print $1'} > /tmp/audit.log ... (2 Replies)
Discussion started by: galuzan
2 Replies

8. Shell Programming and Scripting

[BASH] read 'line' issue with leading tabs and virtual line breaks

Heyas I'm trying to read/display a file its content and put borders around it (tui-cat / tui-cat -t(ypwriter). The typewriter-part is a 'bonus' but still has its own flaws, but thats for later. So in some way, i'm trying to rewrite cat using bash and other commands. But sadly it fails on... (2 Replies)
Discussion started by: sea
2 Replies

9. UNIX for Beginners Questions & Answers

Performance issue to read line by line

Hi All- we have performance issue in unix to read line by line. I am looking at processing all the records. description: Our script will read data from a flat file, it will pickup first four character and based on the value it will set up variables accordingly and appended the final output to... (11 Replies)
Discussion started by: balu1729
11 Replies

10. Shell Programming and Scripting

Performance issue - to read line by line

All- We have a performance issue in reading a file line by line. Please find attached scripts for the same. Currently it is taking some 45 min to parse "512444" lines. Could you please have a look at it and provide any suggestions to improve the performance. Thanks, Balu ... (12 Replies)
Discussion started by: balu1729
12 Replies
All times are GMT -4. The time now is 06:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy