Sponsored Content
Top Forums Shell Programming and Scripting Limit the number of characters in bash output Post 302920785 by Shadow_Reaper on Sunday 12th of October 2014 10:57:59 PM
Old 10-12-2014
Limit the number of characters in bash output

Hi, I need some help with this:
I'm making a script which does a couple of things with image files. The script is supposed to echo the number of each image it is processing like this:

Code:
Processing image1.jpg

The problem is with images with very long filenames, so I want to know how to limit the numer of characters of the output (maybe with sed or awk, but I prefer sed if it's possible).
I want to be able to turn this:

"Processing a-very-very-very-long-crazy-filename.jpg"

into this:

Code:
Processing a-very-very-ve...

It's important to say that this limitation will be done over a variable and not a file.
I came across this solution which seems to work but it is applied on a file and not on a variable, and I need it to be applied on a variable

I'm doing this as part of a progress bar solution. I want it to be like pacman progress bar when downloading packages to be updated except that I want it to inform each processed file and the operation percentage in one line. I already accomplished this, the only things remaining are the one I'm asking for, and the animation of the progress bar to make it look like the pacman one.

Thanks in advance. Shadow_Reaper

---------- Post updated at 11:57 PM ---------- Previous update was at 11:53 PM ----------

The image I posted was intended to show the url of the solution. I will post it through this reply so that it can be seen

[THIS WEBSITE]

/shell-programming

-and-scripting/241327-li

mit-string-length-sed [.HTML HERE]

The actual solution is the first reply but I need to be able to do this on a variable rather than a file.

Last edited by Don Cragun; 10-13-2014 at 12:01 AM.. Reason: Chane IMG tag to URL tag.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Limit of no of characters PER LINE in a unix file

Hi , Whats the limit of characters PER LINE in a unix file , allowed for editing..sort , cut , sed , awk etc (5 Replies)
Discussion started by: mohapatra
5 Replies

2. AIX

Is the Length of User ID for AIX Limit to 8 Characters?

Hi, I'm using AIX version 5.3 currently. I'm trying to create a user id, e.g. andyleong, which the system prompted the length is too long. 1. I would like to know is that the length of user id is limited to maximum 8 characters for AIX. 2. Is it apply to all versions of AIX? If no... (2 Replies)
Discussion started by: meihua_t
2 Replies

3. UNIX for Dummies Questions & Answers

Number of long limit

Hi Hi! I'm currently using AIX 5.2 and would like to know where can i find to see that there's a restriction on the number of login times a user can have. Example, I want give a 2 login per user but some one to give 3 login and some one have to give unlit login time (without logging off the... (2 Replies)
Discussion started by: herath
2 Replies

4. Solaris

How to limit number of Commands

Is there a way that I can limit number of commands that one user can run during period of time. For example Max 10 commands per senconds.:) (3 Replies)
Discussion started by: winger0608
3 Replies

5. HP-UX

cron 80 characters limit

Hello everyone. I am trying to set up a monitor based on a "top" command statistic as follows: top -bc -n1 > output.txt I've put this command into a small script which is called by a cron... but there is something strange happening: the cron is limiting the output to output.txt to 80... (3 Replies)
Discussion started by: MartinF
3 Replies

6. Shell Programming and Scripting

Limit on Number of characters in a line - Vi editor

In the vi editor, there seems to be some limit on the number of characters could be allowed in single line. I tried a line with characters up to 1880. It worked. But when i tried with something of 5000 characters, it doesnt work. Any suggestions. Thanks in advance! (2 Replies)
Discussion started by: nram_krishna@ya
2 Replies

7. UNIX for Dummies Questions & Answers

Limit the number of characters in a bash output

I have a script that outputs the weather on two lines. If possibly I would like to set a character limit on them Currently it outputs something like but I would like to limit the lines so appends an ellipsis if nescessary: This is the script #! /bin/bash curl -s --connect-timeout... (2 Replies)
Discussion started by: Light_
2 Replies

8. UNIX for Dummies Questions & Answers

Limit reoccurrance of characters in lines

Hey guys and gals, Working on a script to limit the reoccurrance of characters in a line. sed "/\(.\).*\1/d" -i file.txt sed "/\(.\).*\1.*\1/d" -i file.txt sed "/\(.\).*\1.*\1.*1/d" -i file.txt .. To limit character reoccurance with 1x, 2x, 3x etc. However I would like to be able to... (2 Replies)
Discussion started by: TAPE
2 Replies

9. UNIX for Dummies Questions & Answers

Limit Number of files

hi guys how can i limit number of files in a disk or partition ? or how can i make a limit to inode number for a disk or partition ? ext3 or ext4 file system (1 Reply)
Discussion started by: mhs
1 Replies

10. Shell Programming and Scripting

How to count number of characters of wc -l output?

I want count number of characters / find the length of the 'wc -l' output This is the command bash-3.2$ gzcat /home/sid/file1.dat |wc -l 830752 So final out I want is 6 i.e lenght of 830752 I tried with awk bash-3.2$ gzcat /home/sid/file1.dat |wc -l | awk '{print length ($0)... (3 Replies)
Discussion started by: sidnow
3 Replies
ttk::progressbar(n)						 Tk Themed Widget					       ttk::progressbar(n)

__________________________________________________________________________________________________________________________________________________

NAME
ttk::progressbar - Provide progress feedback SYNOPSIS
ttk::progressbar pathName ?options? _________________________________________________________________ DESCRIPTION
A ttk::progressbar widget shows the status of a long-running operation. They can operate in two modes: determinate mode shows the amount completed relative to the total amount of work to be done, and indeterminate mode provides an animated display to let the user know that something is happening. STANDARD OPTIONS
-class -cursor -takefocus -style See the ttk_widget manual entry for details on the standard options. WIDGET-SPECIFIC OPTIONS [-orient orient] One of horizontal or vertical. Specifies the orientation of the progress bar. [-length length] Specifies the length of the long axis of the progress bar (width if horizontal, height if vertical). [-mode mode] One of determinate or indeterminate. [-maxi- mum maximum] A floating point number specifying the maximum -value. Defaults to 100. [-value value] The current value of the progress bar. In determinate mode, this represents the amount of work completed. In indeterminate mode, it is interpreted modulo -maximum; that is, the progress bar completes one "cycle" when the -value increases by -maximum. [-variable variable] The name of a global Tcl variable which is linked to the -value. If specified, the -value of the progress bar is automatically set to the value of the variable whenever the latter is modified. [-phase phase] Read-only option. The widget periodically increments the value of this option whenever the -value is greater than 0 and, in determinate mode, less than -maximum. This option may be used by the current theme to provide additional animation effects. WIDGET COMMAND
pathName cget option Returns the current value of the specified option; see ttk::widget(n). pathName configure ?option? ?value option value ...? Modify or query widget options; see ttk::widget(n). pathName identify x y Returns the name of the element at position x, y. See ttk::widget(n). pathName instate statespec ?script? Test the widget state; see ttk::widget(n). pathName start ?interval? Begin autoincrement mode: schedules a recurring timer event that calls step every interval milliseconds. If omitted, interval defaults to 50 milliseconds (20 steps/second). pathName state ?stateSpec? Modify or query the widget state; see ttk::widget(n). pathName step ?amount? Increments the -value by amount. amount defaults to 1.0 if omitted. pathName stop Stop autoincrement mode: cancels any recurring timer event initiated by pathName start. SEE ALSO
ttk::widget(n) Tk 8.5 ttk::progressbar(n)
All times are GMT -4. The time now is 06:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy