build a string of asterisks elegantly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting build a string of asterisks elegantly
# 15  
Old 02-17-2012
Code:
$
$
$ LINE=`yes "*" | head -50 | tr -d '\n'`
$
$ echo "$LINE"
**************************************************
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
# 16  
Old 02-17-2012
Quote:
Originally Posted by Scrutinizer
Code:
echo | awk NF=51 OFS=\*

Code:
c=50
echo | awk NF=$c+1 OFS=\*

Note that this solution does not work on all versions of awk. It works for gawk. oawk prints an empty string.
# 17  
Old 02-17-2012
Quote:
Originally Posted by Scrutinizer
Code:
echo | awk '$50=OFS="*"'

That's a very slick solution. Great job.

Regards,
Alister

---------- Post updated at 10:02 AM ---------- Previous update was at 09:53 AM ----------

Quote:
Originally Posted by fpmurphy
Note that this solution does not work on all versions of awk. It works for gawk. oawk prints an empty string.
It should work with any AWK that intends to be POSIX compliant. I'm not familiar with oawk, but if it endeavours to follow POSIX, it's a bug. Testing confirms that gawk, mawk, and nawk are compliant.

Looking back, this behavior was documented at least 15 years ago in SUSv2, if not earlier. So, it's nothing new and not a case of an active implementation being in the process of catching up: http://pubs.opengroup.org/onlinepubs...9/xcu/awk.html

Regards,
Alister

Last edited by alister; 02-17-2012 at 11:09 AM..
This User Gave Thanks to alister For This Post:
# 18  
Old 02-17-2012
Hi.

Here is a longer, more general solution, changeable from the command line:
Code:
#!/usr/bin/env bash

# @(#) s1   Demonstrate creation of simple data files.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
edges() { local _f _n _l;: ${1?"edges: need file"}; _f=$1;_l=$(wc -l $_f);
  head -${_n:=3} $_f ; pe "--- ( $_l: lines total )" ; tail -$_n $_f ; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C ./spit

pl " Results, default:"
./spit 

pl " Results, 2 x 3, value 1.5:"
./spit -r 2 -c 3 -v 1.5

pl " Results, one row of character data:"
./spit -d "" --rows 1 --cols 20 -v '*'

exit 0

producing:
Code:
% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
bash GNU bash 3.2.39
./spit spit - ( local: RepRev 1.3, ./spit, 2012-02-17 )

-----
 Results, default:
1

-----
 Results, 2 x 3, value 1.5:
1.5 1.5 1.5
1.5 1.5 1.5

-----
 Results, one row of character data:
********************

I have needed data files for testing often enough that this is useful for me. Perhaps it will be useful for others ... cheers, drl

Download spit.txt, rename as "spit", chmod +x spit, run a test script. As usual no warranty, use at your risk.
# 19  
Old 02-18-2012
Quote:
It should work with any AWK that intends to be POSIX compliant. I'm not familiar with oawk, but if it endeavours to follow POSIX, it's a bug. Testing confirms that gawk, mawk, and nawk are compliant.
oawk is the old pre-POSIX original implementation of awk. nawk is new awk from the AT&T Porgrammers Workbench. nawk was reference implementation for the POSIX awk specification. Unix operating systems often ship with both versions.
This User Gave Thanks to fpmurphy For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replacing multiple asterisks in vi

i need to replace all occurrences of "period asterisk" as it is shown in this: blah blah .*:.*:.* blah blah with: :: so that the end result looks like this: blah blah :: blah blah I tried different variations of the following but it didint work: %s_ .*:.*:.* _ :: _g (2 Replies)
Discussion started by: SkySmart
2 Replies

2. UNIX for Advanced & Expert Users

Show Asterisks when changing Password

Note: **Showing Asterisks when using SUDO is not what I am looking for. That method is well documented** Short Description: We have a requirement where users want to see that they are typing a password when logging into a RedHat box or when they are changing their password -- instead of... (1 Reply)
Discussion started by: caperjm
1 Replies

3. Shell Programming and Scripting

Eliminate or ignore asterisks in data when parsing

I have data file that has this in it: data.txt ......... ......... PPJ97**2017PPJ97**2017-03-21-13.35.15.887208********************START ERROR LOGGING****************** PPJ97**2017-03-21-13.35.15.887208** PROMPT APPLICATION ERROR ** PPJ97**2017-03-21-13.35.15.887208** IN TIMESTAMP |... (1 Reply)
Discussion started by: SkySmart
1 Replies

4. UNIX for Dummies Questions & Answers

Adding SDK Build on Kernel Source Build

Hi, So I downloaded this kernel source and was able to build it successfully. But I want to add this SDK source code inside, can anyone help me how to do this? Note that the SDK source can be built by itself. I added the SDK in the main Makefile: init-y := init/ #added SDK... (0 Replies)
Discussion started by: h0ujun
0 Replies

5. Shell Programming and Scripting

Create new file when three asterisks are encountered.

Hi All, I have a text file which is currently formatted like this: TEXT1 *** TEXT2 *** TEXT3 *** I want text before *** to go into separate files. For example, 1.dat TEXT1 (5 Replies)
Discussion started by: shoaibjameel123
5 Replies

6. Shell Programming and Scripting

need to replace asterisks

I need to replace occurrences of twelve asterisks "************" with the string " 0000000.00" . Note that there are two spaces in front of the first zero. How can I do this using awk or sed? (3 Replies)
Discussion started by: mustang_9333
3 Replies

7. Shell Programming and Scripting

how to build a pipe delimited string

#! /bin/csh set delimiter = | foreach i (*) set str_deli="$i$delimiter" question: how to retain the value of str_deli so i can build a pipe delimited string? end (1 Reply)
Discussion started by: jdsignature88
1 Replies

8. Shell Programming and Scripting

Assistence With Using Asterisks in GREP Expressions

I am attempting to find all complete words which contain an asterisk at the beginning and the end - for instance, "*Hello?*" or "*you*". From what I've read, I would have thought that the following expression would do that just fine: \<\*.*\*\> \< denoting the beginning of a word. \*... (12 Replies)
Discussion started by: MagusScythe
12 Replies

9. Shell Programming and Scripting

How to build a string in shell script

Hi all, I had a typical problem. I am using a parameter PK="PK1 PK2 PK3" i need to build the string a.PK1=b.PK1 and a.PK2=b.PK2 and a.PK3=b.PK3 Please help (8 Replies)
Discussion started by: nkosaraju
8 Replies

10. Shell Programming and Scripting

Double asterisks

When I go$ echo *I get a directory listing. When I go$ echo * *I get a directory listing, followed by a second identical directory listing. When I go$ echo **I only get one directory listing. What happens to the second asterisk in this case? Why doesn't it expand? I haven't been able to sleep... (2 Replies)
Discussion started by: na5m
2 Replies
Login or Register to Ask a Question